Skip to content

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

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

Closed
spring-projects-issues opened this issue Feb 10, 2015 · 10 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 10, 2015

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:

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 23, 2015

Sam Brannen commented

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

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

JDK proxy. You can find the ignored tests here

Just run them and you'll see by yourself.

@spring-projects-issues
Copy link
Collaborator Author

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!

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 21, 2015

Sam Brannen commented

This is related to #17534.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 21, 2015

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? ;-)

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 22, 2015

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?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 22, 2015

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 22, 2015

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.

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) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants