Skip to content

AnnotationUtils.findAnnotation() should support arbitrary levels of meta-annotations [SPR-11448] #16074

Closed

Description

@spring-projects-issues

Sam Brannen opened SPR-11448 and commented

Status Quo

AnnotationUtils.findAnnotation(Class, Class) claims to recursively search through all declared annotations; however, only one level of annotations is supported by the algorithm.

In other words, meta-annotations on meta-annotations will never be found.

Deliverables

  1. Alter the search algorithm in AnnotationUtils.findAnnotation(Class, Class) so that arbitrary levels of meta-annotations (e.g., meta-annotations on meta-annotations) are supported.

Affects: 3.0 GA

Issue Links:

Referenced from: commits 42a3634

Activity

  1. spring-projects-issues commented on Feb 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Fixed as described in the comments for GitHub commit 42a3634:

    Support nested meta-annotations in AnnotationUtils

    Prior to this commit, AnnotationUtils.findAnnotation(Class, Class)
    claimed to recursively search through annotations; however, only one
    level of annotations was supported by the algorithm.

    This commit alters the search algorithm so that nested meta-annotations
    (i.e., meta-annotations on meta-annotations) are also supported.

  2. spring-projects-issues commented on Feb 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    While this is clearly a mismatch between documentation and behavior, I'd consider it an improvement at this point. The previous behavior was functionally alright for many purposes, it seems, and what we're really doing is to consistently extend our reflection-based search to arbitrary meta-depths now. Our ASM-based annotation checks are a different matter in any case.

    In that sense, let's consider this a major improvement, not a minor bug.

    Juergen

  3. spring-projects-issues commented on Feb 20, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Juergen, thanks for the feedback!

    Here's a bit of additional background information...

    This functionality is actually required by #14588. The new @BootstrapWith annotation is used as a meta-annotation on @WebAppConfiguration. So when @WebAppConfiguration is itself used as a meta-annotation on a custom composed annotation, AnnotationUtils.findAnnotation() was not able to find @BootstrapWith before this change. In contrast, AnnotatedElementUtils.getAnnotationAttributes() is able to find @BootstrapWith; however, @BootstrapWith only has a value attribute. Thus using AnnotatedElementUtils is not a solution in such cases since it does not support value attributes.

  4. spring-projects-issues commented on Feb 20, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue is conceptually related to #16020 with regard to value attributes on meta-annotations.

  5. added
    type: enhancement
    in: core
    on Jan 11, 2019
  6. 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: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions