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

Annotations on generic interface methods not found by AnnotationUtils [SPR-16060] #20609

Closed
spring-projects-issues opened this issue Oct 11, 2017 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 11, 2017

Christopher Rued opened SPR-16060 and commented

When scanning for annotations on a class that implements a generic interface where the generic
type is specified in the implementing class, annotation scanning would fail to identify annotations
from the interface since the parameter types do not match.

For example, given an interface:

public interface Foo<T> {
    @Order
    void foo(T t);
}

and a class:

public class StringFoo implements Foo<String> {
    public void foo(String s) { ... }
}

when scanning StringFoo.foo for annotations, no annotations were identified.

This commit changes annotation scanning so that when scanning for annotations, the parameters are
compared for assignability (using Class.isAssignableFrom()) rather than requiring exact matches.

Original Issue: SEC-3081


Issue Links:

Referenced from: pull request #1553, and commits 23d4862, b72594d

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 11, 2017

Christopher Rued commented

PR #1553

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 16, 2018

Christopher Rued commented

Just following up, since I haven't seen any activity. This can cause some surprising bugs that are hard to notice. Let me know if you need any changes in the pull request.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 18, 2018

Juergen Hoeller commented

It turns out that #21271 makes this straightforward and efficient to implement, so I'll even backport this to 5.0.8. The pain is that an assignability check is not sufficient here; we'll have to go through generics resolution for the type variable to make sure that our concrete method actually overrides the given interface methods (i.e. that it is not just an overloaded variant of it).

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants