Do not render meta-annotations for AOT repository method parameters#3511
Open
seonwooj0810 wants to merge 1 commit into
Open
Do not render meta-annotations for AOT repository method parameters#3511seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
`MethodMetadata.buildParameter(…)` iterates `MergedAnnotations.from(parameterAnnotations)`, which also exposes meta-annotations. As a result a parameter annotated with, e.g., `jakarta.validation.constraints.@NotNull` caused its meta-annotation `@jakarta.validation.Constraint` to be rendered standalone into the generated repository source, producing uncompilable code (`annotation @jakarta.validation.Constraint is missing a default value for the element 'validatedBy'`) and failing AOT/native processing. Only render directly-present annotations; meta-annotations remain discoverable through the concrete annotation itself. Closes spring-projects#3499 Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
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.
Fixes #3499
Root cause
MethodMetadata.buildParameter(…)(added in 852d789 to render query-method parameter annotations for AOT repositories) iteratesMergedAnnotations.from(methodParameter.getParameterAnnotations()).MergedAnnotationsalso exposes meta-annotations, so for a parameter annotated with e.g.jakarta.validation.constraints.@NotNull, its meta-annotation@jakarta.validation.Constraintwas rendered standalone into the generated repository source. Because@Constrainthas a mandatoryvalidatedByelement,process-aot/ native builds fail to compile the generated code:This is a regression: repositories with
jakarta.validation.constraints.*parameters that built with 4.0.3 broke on 4.0.6.Change
Only render directly-present annotations (
MergedAnnotation#isDirectlyPresent()). Meta-annotations remain discoverable through the concrete annotation itself, so the introspection intent of #3458 is preserved while the invalid standalone meta-annotation is no longer emitted.Tests
Added
MethodMetadataUnitTests#doesNotRenderMetaAnnotations, which declares a parameter annotated with a meta-annotated annotation (mirroring how@NotNullis meta-annotated with@Constraint) and asserts only the directly-present annotation is rendered. The test fails before the change and passes after.Verification done
buildParameteron currentmain.main, passes with the fix.MethodMetadataUnitTests,AotRepositoryMethodBuilderUnitTests,MethodContributorUnitTests,RepositoryContributorUnitTests— all green.