Repository navigation
Conversation
AFPResourceManager keeps trailer fonts in a HashMap keyed by AFPResourceInfo, whose hashCode includes the ResourceType enum's identity hash. The order the fonts are written in, and the generated resource names, therefore depend on what the JVM did before the enum was first hashed. The same input can produce different AFP bytes in different runs. A LinkedHashMap writes the fonts in the order they were first used. Co-authored-by: claude-opus-5.5 <claude-opus-5.5@users.noreply.github.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since FOP-3337 (commit feb2323),
AFPResourceManagercollects embedded TrueType fonts intrailerFonts, aHashMap<AFPResourceInfo, AFPTrailerFont>, and writes them in the map's iteration order inwriteToStream().AFPResourceInfo.hashCode()includesAFPResourceLevel.hashCode(), which includesResourceType.hashCode(). That is an enum, so its hash is an identity hash, and its value depends on what the JVM did before the enum was first hashed. As a result, the order of the TrueType font objects in the resource group, and theRES/OCnames they get, can differ between runs for the same input. The pages render the same, but the AFP bytes don't. We hit this in byte-level regression tests after upgrading from 2.11 to 2.12: the same document produced different output depending on which tests had run earlier in the JVM.This changes
trailerFontsto aLinkedHashMap, so fonts are written in the order they were first registered.Checked by rendering an invoice with several TrueType fonts to AFP on 2.12, with and without this class patched in, in JVMs that ran different sets of work first. Unpatched, the output differed between those JVMs. Patched, it was byte-identical every time.