Fix AnnotationTemplateGenerator to handle nested annotations correctly#5713
Merged
knutwannheden merged 6 commits intomainfrom Jul 7, 2025
Merged
Fix AnnotationTemplateGenerator to handle nested annotations correctly#5713knutwannheden merged 6 commits intomainfrom
AnnotationTemplateGenerator to handle nested annotations correctly#5713knutwannheden merged 6 commits intomainfrom
Conversation
The `AnnotationTemplateGenerator` was failing with an `IndexOutOfBoundsException` when processing nested
annotations (e.g., repeatable annotations within annotation arrays). This occurred because the template
generator couldn't find a "typical annotation target" for annotations nested inside other annotations' array
values.
The fix adds proper handling for nested annotations by:
1. Walking up the parent hierarchy to find the ultimate annotation target (method, variable, or class)
2. Adding a fallback case that generates `@interface $Placeholder {}` when no typical target can be found
3. Updating both the `template()` and `cacheKey()` methods to handle nested annotation cases consistently
This ensures that `JavaTemplate` can successfully process and transform nested annotations without throwing
exceptions.
Added a test case that demonstrates the fix by transforming nested repeatable annotations' attributes using
`JavaTemplate`.
Fixes:
- #5712
timtebeek
reviewed
Jul 4, 2025
timtebeek
approved these changes
Jul 4, 2025
Member
timtebeek
left a comment
There was a problem hiding this comment.
Approved already; could merge as is, but wasn't sure given that you had marked this as a draft.
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.
The
AnnotationTemplateGeneratorwas failing with anIndexOutOfBoundsExceptionwhen processing nestedannotations (e.g., repeatable annotations within annotation arrays). This occurred because the template
generator couldn't find a "typical annotation target" for annotations nested inside other annotations' array
values.
The fix adds proper handling for nested annotations by:
@interface $Placeholder {}when no typical target can be foundtemplate()method to handle nested annotation cases consistentlyThis ensures that
JavaTemplatecan successfully process and transform nested annotations without throwingexceptions.
Added a test case that demonstrates the fix by transforming nested repeatable annotations' attributes using
JavaTemplate.AnnotationTemplateGeneratordoes not handle nested annotations correctly #5712