Skip to content

SPR-16060 - Enhance AnnotationUtils to find annotations on generic interfaces #1553

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

Conversation

christor
Copy link

@christor christor commented Oct 11, 2017

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.

Issue: SEC-3081

@pivotal-issuemaster
Copy link

@christor Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@christor Thank you for signing the Contributor License Agreement!

@christor
Copy link
Author

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.

Issue: SEC-3081

Correct formatting
@christor christor force-pushed the sec-3081-find-annotations-on-generic-interfaces branch from 1221870 to b121c50 Compare October 11, 2017 03:29
@sbrannen
Copy link
Member

Hi @christor,

Since your proposed change is in the core Spring Framework and not in Spring Security, please create a JIRA issue for the SPR project so that we can track it there.

Cheers,

Sam

@christor
Copy link
Author

christor commented Oct 11, 2017

Done, @sbrannen - https://jira.spring.io/browse/SPR-16060

Is there anything more that needs to be done?

@snicoll snicoll changed the title Enhance AnnotationUtils to find annotations on generic interfaces SPR-16060 - Enhance AnnotationUtils to find annotations on generic interfaces Oct 16, 2017
@christor
Copy link
Author

christor commented Nov 2, 2017

Just following up to see if there's anything more needed.

@sbrannen
Copy link
Member

sbrannen commented Nov 2, 2017

Thanks for raising the JIRA issue!

AFAIK, @jhoeller is going to look into this.

@christor
Copy link
Author

christor commented Jan 4, 2018

Just checking in again, since it's been a couple of months. Does this change look reasonable, @jhoeller?

@christor
Copy link
Author

Looks like some other commit has caused a conflict. If/when you want to merge this I can help resolve those.

@JacobBrandt
Copy link

Yea this one just bit me as well. @sbrannen @jhoeller how long are we expected to wait? It's been quite awhile. I just ran into this with Pre/PostAuthorize annotations. It's not a great problem to run into for these kinds of annotations.

@sbrannen
Copy link
Member

SPR-16060 is scheduled for 5.1 RC1.

So that means it's on the radar, but I'll let @jhoeller comment on an ETA in 5.1 snapshots.

@jhoeller
Copy link
Contributor

Finally resolved in master now, and scheduled for a backport to 5.0.8. The implementation is somewhat different since it goes through generics resolution for the type variable instead of an assignability check. Thanks for the pull request, in any case!

@jhoeller jhoeller closed this Jul 18, 2018
@christor
Copy link
Author

Great news, thanks!

I guess this is the relevant change? d78e27f#diff-44945edabd4176dfd3966252ff4a589e

@jhoeller
Copy link
Contributor

jhoeller commented Jul 18, 2018

It's a follow-up to that which is actually pushed to master now: 23d4862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants