Skip to content

Commit 5018889

Browse files
committed
AnnotationAttributesReadingVisitor defensively handles meta-annotation retrieval failure
Issue: SPR-12493
1 parent 1aad4da commit 5018889

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public static <T extends Annotation> T getAnnotation(AnnotatedElement annotatedE
131131
/**
132132
* Get all {@link Annotation Annotations} from the supplied Method, Constructor or Field.
133133
* @param annotatedElement the Method, Constructor or Field to retrieve annotations from
134-
* @return the annotations found
134+
* @return the annotations found, or {@code null} if not resolvable (e.g. because nested
135+
* Class values in annotation attributes failed to resolve at runtime)
135136
* @since 4.0.8
136137
*/
137138
public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) {

spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.core.annotation.AnnotationAttributes;
2727
import org.springframework.core.annotation.AnnotationUtils;
2828
import org.springframework.util.MultiValueMap;
29+
import org.springframework.util.ObjectUtils;
2930

3031
/**
3132
* ASM visitor which looks for the annotations defined on a class or method, including
@@ -72,9 +73,12 @@ public void doVisitEnd(Class<?> annotationClass) {
7273
attributes.add(0, this.attributes);
7374
}
7475
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
75-
for (Annotation metaAnnotation : AnnotationUtils.getAnnotations(annotationClass)) {
76-
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
77-
recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
76+
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
77+
if (!ObjectUtils.isEmpty(metaAnnotations)) {
78+
for (Annotation metaAnnotation : metaAnnotations) {
79+
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
80+
recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
81+
}
7882
}
7983
}
8084
if (this.metaAnnotationMap != null) {

0 commit comments

Comments
 (0)