You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AnnotationUtils.findAnnotation() should support arbitrary levels of meta-annotations [SPR-11448] #16074
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
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.
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.
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.
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.
Activity
spring-projects-issues commentedon Feb 19, 2014
Sam Brannen commented
Fixed as described in the comments for GitHub commit 42a3634:
spring-projects-issues commentedon Feb 19, 2014
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
spring-projects-issues commentedon Feb 20, 2014
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
@BootstrapWithannotation is used as a meta-annotation on@WebAppConfiguration. So when@WebAppConfigurationis itself used as a meta-annotation on a custom composed annotation,AnnotationUtils.findAnnotation()was not able to find@BootstrapWithbefore this change. In contrast,AnnotatedElementUtils.getAnnotationAttributes()is able to find@BootstrapWith; however,@BootstrapWithonly has avalueattribute. Thus usingAnnotatedElementUtilsis not a solution in such cases since it does not supportvalueattributes.spring-projects-issues commentedon Feb 20, 2014
Sam Brannen commented
This issue is conceptually related to #16020 with regard to
valueattributes on meta-annotations.