Stop implementing SynthesizedAnnotation in annotation proxies #29041
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.
Overview
This PR has two commits: one that stops using
SynthesizedAnnotation
and a second that deprecatesSynthesizedAnnotation
.If we decide to get rid of
SynthesizedAnnotation
, we can subsequently remove it completely for Spring Framework 6.0.Discussion
SynthesizedAnnotation
was originally introduced as a convenience for easily detecting if an annotation had been synthesized by Spring via a simpleif (myAnnotation instanceof SynthesizedAnnotation)
check.However, the introduction of
SynthesizedAnnotation
in the JDK proxy for an annotation results in a separate proxy class for Spring's synthesized annotations, and this causes issues with GraalVM native images since users and framework developers must always ensure that the additional proxy classes are registered.This PR completely removes the use of
SynthesizedAnnotation
in synthesized proxies which allows the JDK proxy class for the annotation to be reused within a GraalVM native image. See this project for a demonstration.Instead of checking if an annotation implements
SynthesizedAnnotation
(to determine if the annotation needs to be synthesized), the PR uses aProxy.getInvocationHandler(annotation) instanceof SynthesizedMergedAnnotationInvocationHandler)
check to determine if Spring synthesized the annotation.Drawbacks
At one point in 2015, @jhoeller used
Proxy.getInvocationHandler
to perform the "is synthesized" check; however, he reverted that due to #18402. See #18402 (comment) for details.Related Issues
Deliverables
Proxy.getInvocationHandler
work without negative side effects such as those raised in #18402