Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop implementing SynthesizedAnnotation in annotation proxies #29041

Closed

Conversation

sbrannen
Copy link
Member

@sbrannen sbrannen commented Aug 29, 2022

Overview

This PR has two commits: one that stops using SynthesizedAnnotation and a second that deprecates SynthesizedAnnotation.

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 simple if (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 a Proxy.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

  • Determine if we can make Proxy.getInvocationHandler work without negative side effects such as those raised in #18402

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement for: team-meeting theme: aot An issue related to Ahead-of-time processing labels Aug 29, 2022
@sbrannen sbrannen added this to the Triage Queue milestone Aug 29, 2022
@sbrannen sbrannen requested a review from jhoeller August 29, 2022 16:57
@sbrannen sbrannen self-assigned this Sep 1, 2022
@sbrannen sbrannen modified the milestones: Triage Queue, 6.0.0-M6 Sep 1, 2022
@sbrannen sbrannen removed the request for review from jhoeller September 1, 2022 14:45
@sbrannen sbrannen closed this in 0ec03a8 Sep 2, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Sep 2, 2022
Since Spring no longer adds the SynthesizedAnnotation interface to the
JDK dynamic proxy used to synthesize an annotation, this commit
officially deprecates SynthesizedAnnotation and related methods in
RuntimeHintsUtils.

See spring-projectsgh-29041, spring-projectsgh-29054
Closes spring-projectsgh-29053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant