Skip to content

Do not render meta-annotations for AOT repository method parameters#3511

Open
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:fix/gh-3499-aot-param-meta-annotations
Open

Do not render meta-annotations for AOT repository method parameters#3511
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:fix/gh-3499-aot-param-meta-annotations

Conversation

@seonwooj0810

Copy link
Copy Markdown

Fixes #3499

Root cause

MethodMetadata.buildParameter(…) (added in 852d789 to render query-method parameter annotations for AOT repositories) iterates MergedAnnotations.from(methodParameter.getParameterAnnotations()). MergedAnnotations also exposes meta-annotations, so for a parameter annotated with e.g. jakarta.validation.constraints.@NotNull, its meta-annotation @jakarta.validation.Constraint was rendered standalone into the generated repository source. Because @Constraint has a mandatory validatedBy element, process-aot / native builds fail to compile the generated code:

annotation @jakarta.validation.Constraint is missing a default value for the element 'validatedBy'

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 @NotNull is meta-annotated with @Constraint) and asserts only the directly-present annotation is rendered. The test fails before the change and passes after.

Verification done

  • Reproduced the meta-annotation expansion in buildParameter on current main.
  • New regression test fails on unpatched main, passes with the fix.
  • Re-ran MethodMetadataUnitTests, AotRepositoryMethodBuilderUnitTests, MethodContributorUnitTests, RepositoryContributorUnitTests — all green.

`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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOT repository generation emits invalid @Constraint annotation alongside jakarta.validation.constraints.* parameters

2 participants