Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Oct 11, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Christopher Rued commented

    PR #1553

  2. spring-projects-issues commented on Feb 16, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on Jul 18, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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).

  4. added
    type: enhancement
    in: core
    on Jan 11, 2019
  5. added this to the 5.0.8 milestone 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: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions