Walk JavaType refs embedded in annotation element values#7426
Merged
knutwannheden merged 1 commit intomainfrom Apr 19, 2026
Merged
Walk JavaType refs embedded in annotation element values#7426knutwannheden merged 1 commit intomainfrom
JavaType refs embedded in annotation element values#7426knutwannheden merged 1 commit intomainfrom
Conversation
JavaTypeVisitor.visitAnnotation only visited annotation.getType(), leaving any JavaType refs in element values untouched: the element meta-variable, SingleElementValue.referenceValue, SingleElementValue.constantValue (when it's a JavaType), and ArrayElementValue's referenceValues / JavaType-valued constantValues. Downstream visitors that rely on the full-graph walk (dedup, type remappers, serializers) silently see non-canonical instances inside annotation values while the rest of the type graph is consistent. Adds visitAnnotationElementValue, which visits every ref kind and reconstructs the ElementValue only when a returned instance differs. UnsafeJavaTypeVisitor inherits this via the default visitAnnotation.
JavaType refs embedded in annotation element values
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.
What's changed?
JavaTypeVisitor.visitAnnotationonly visitedannotation.getType(), leaving the refs inside element values untouched: theelementmeta-variable andSingleElementValue.referenceValue/ArrayElementValue.referenceValues. Any downstream visitor that relies on the full-graph walk (dedup, type remappers, serializers, …) sees non-canonical instances inside annotation values while the rest of the type graph is consistent.Adds
visitAnnotationElementValue, which visits the element meta-variable and the reference-value branch, and reconstructs theElementValueonly when a returned instance changed identity.UnsafeJavaTypeVisitorinherits the new behaviour through the defaultvisitAnnotation.Constant values are deliberately not visited:
SingleElementValue.from/ArrayElementValue.fromroute anyJavaType-valued argument into the reference branch, so constants only ever hold primitives, strings, and enums in parser-produced LSTs.What's your motivation?
Downstream at Moderne, a recipe run against a large multi-module LST failed deserializing a method's annotations — the
meta.bintype table referenced an index past its own end. Root cause was ourJavaTypeDeduplicationVisitorinheriting this visit gap: annotation-value refs stayed as pre-canonical instances while the rest of the type graph was deduped, so the writer's identity-keyed map treated them as fresh types after the offset table had already been sized.Fixing only in our downstream visitor leaves the gap in every other
JavaTypeVisitorsubclass, which is why this PR is here.Anything in particular you'd like reviewers to focus on?
from(...)factories.ArrayElementValuereference-values loop returns the same array when every visited element is identity-equal, and only clones when at least one changed.