Skip to content

AnnotatedElementUtils does not find annotations on methods in dynamic proxies [SPR-12703] #17300

Closed

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-12703 and commented

The following two calls do not yield consistent results when the method is a method of a dynamic proxy.

AnnotatedElementUtils.getAnnotationAttributes(this.method, FooBar.class.getName());

The above returns null; whereas, the following call on the same method returns the FooBar annotation instance.

AnnotationUtils.findAnnotation(this.method, FooBar.class)

The code merged for #16696 has some TODOs in ApplicationListenerMethodAdapter and tests that expose this behavior (removing the call to AnnotationUtils will fail with a NullPointerException).


Affects: 4.1 GA

Issue Links:

Activity

  1. spring-projects-issues commented on Feb 23, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    What type of proxy is being used here: CGLIB, JDK dynamic proxy, or AspectJ LTW?

  2. spring-projects-issues commented on Feb 23, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue is perhaps a duplicate of #15734 or #17335 and at the very least related to those two issues.

  3. spring-projects-issues commented on Feb 24, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    JDK proxy. You can find the ignored tests here

    Just run them and you'll see by yourself.

  4. spring-projects-issues commented on Apr 19, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Is this one still on the agenda? There is a TODO in the event listener infra (new in 4.2) that really does require this fix. Thanks!

  5. spring-projects-issues commented on Apr 20, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Yes, this is still on the agenda for 4.2 RC1!

  6. spring-projects-issues commented on Apr 21, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This is related to #17534.

  7. spring-projects-issues commented on Apr 21, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    JDK proxy. You can find the ignored tests here

    Just run them and you'll see by yourself.

    The ignored tests you linked to have nothing to do with proxies. Rather, the reason they were failing is that AnnotationUtils did not support arbitrary levels of meta-annotations on methods, and this caused the @EventListener not to be seen when used as a meta-meta-annotation. See #17534 for details.

    Now, having cleared that up... do you perhaps have any failing tests related to the proxy issue you describe in this issue's description? ;-)

  8. spring-projects-issues commented on Apr 22, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    well if you have resolved #17534 and the tests are passing now, I guess we can just say that I took the wrong assumptions and that this one is a duplicate. Or am I missing something?

  9. spring-projects-issues commented on Apr 22, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    No, I don't think you're missing something. I just think that you covered two features/bugs in one JIRA issue. ;)

    I solved the first one in #17534, and the other one is related to lacking support for interfaces.

    In this issue you talk specifically about proxies; however, neither AnnotationUtils nor AnnotatedElementUtils provides explicit support for proxies per se. Rather, AnnotationUtils provides support for finding annotations on methods declared in interfaces, which exactly covers the use case for dynamic proxies that implement an annotated interface. So, with that in mind, I'll change the summary and focus of this issue and remove that duplicated deliverable from #17335.

    Sound good?

    Cheers,

    Sam

  10. spring-projects-issues commented on Apr 22, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Resolving as a "Duplicate" of #17335.

    In addition, support for finding annotations at the type level on interfaces is addressed by #17537.

  11. added
    type: bug
    in: core
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions