Skip to content

Annotations on superclasses are detected by StandardAnnotationMetadata [SPR-11595] #16219

Closed

Description

@spring-projects-issues

Phil Webb opened SPR-11595 and commented

Background

The StandardAnnotationMetadata class in Spring Framework 4.0.2 returns false for isAnnotated when a class is not directly annotated with an annotation (even if the annotation is present on a superclass). Furthermore, getAnnotationAttributes and getAllAnnotationAttributes return null when querying for the same annotation.


Analysis

The fix for #16100 changed this logic and is causing problems with Spring Boot conditions. Specifically, @Conditional annotations were never previously considered on super classes (see #15466).


Affects: 4.0.3

Issue Links:

Referenced from: commits a2f1169

Activity

  1. spring-projects-issues commented on Mar 24, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Phil Webb commented

    Sam,

    Take a look at https://github.com/philwebb/spring-framework/tree/SPR-11595 for a test case and potential fix. Unfortunately the fix breaks AnnotatedElementUtilsTests which explicitly tests for the exact opposite of the problem.

    The failing test in Spring Boot that triggered all this is ManagementSecurityAutoConfigurationTests. It returns true for has annotations, but the attribute map doesn't contain a value.

  2. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This has been resolved as described in the comments for GitHub commit a2f1169:

    Don't detect annotations on superclass in StAnMeta

    Changes introduced in conjunction with issue #16100 altered the
    behavior of StandardAnnotationMetadata such that annotations could be
    detected on superclasses, specifically in the case where the
    AnnotatedElementUtils.getAllAnnotationAttributes() method is invoked to
    obtain multiple annotations of the same type (on the lowest level in the
    class hierarchy), as is the case for @Profile and @Conditional.

    This commit partially reverts these changes as follows:

    • All methods in AnnotatedElementUtils now set the
      traverseClassHierarchy to false, thereby effectively reverting the
      changes made in commit 1d30bf8.
      Note, however, that the changes made to AnnotationUtils remain in
      place.

    • Introduced tests in AnnotationMetadataTests that verify behavior
      present in Spring Framework 4.0.2 and earlier.

    • Updated tests in AnnotatedElementUtilsTests so that they pass against
      the reverted changes (i.e., align with the behavior present in Spring
      Framework 4.0.2 and earlier).

    • Refined Javadoc in AnnotationMetadata with regard to annotations
      being "present" vs. "defined".

    • Refined Javadoc in AnnotatedTypeMetadata.

  3. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Phil Webb, please verify the correctness of the changes against the next 4.0.3 snapshot running against Spring Boot.

    Thanks!

    Sam

  4. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Phil Webb commented

    Sam Brannen, The tests all pass now, so it looks good.

  5. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Great! :)

    Thanks for letting me know so quickly.

  6. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Note: #16221 is now a follow up for this issue.

  7. added
    type: regression
    in: core
    on Jan 11, 2019
  8. added this to the 4.0.3 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: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions