From 5018889d7861bc9ee5ecf9d8c4bcc2d208274b9a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 2 Dec 2014 15:12:23 +0100 Subject: [PATCH] AnnotationAttributesReadingVisitor defensively handles meta-annotation retrieval failure Issue: SPR-12493 --- .../core/annotation/AnnotationUtils.java | 3 ++- .../AnnotationAttributesReadingVisitor.java | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 05afe9e368..5393f6849f 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -131,7 +131,8 @@ public abstract class AnnotationUtils { /** * Get all {@link Annotation Annotations} from the supplied Method, Constructor or Field. * @param annotatedElement the Method, Constructor or Field to retrieve annotations from - * @return the annotations found + * @return the annotations found, or {@code null} if not resolvable (e.g. because nested + * Class values in annotation attributes failed to resolve at runtime) * @since 4.0.8 */ public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) { diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java index 4af65e9cf9..6937e811e4 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java @@ -26,6 +26,7 @@ import java.util.Set; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; /** * ASM visitor which looks for the annotations defined on a class or method, including @@ -72,9 +73,12 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib attributes.add(0, this.attributes); } Set metaAnnotationTypeNames = new LinkedHashSet(); - for (Annotation metaAnnotation : AnnotationUtils.getAnnotations(annotationClass)) { - if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) { - recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation); + Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass); + if (!ObjectUtils.isEmpty(metaAnnotations)) { + for (Annotation metaAnnotation : metaAnnotations) { + if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) { + recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation); + } } } if (this.metaAnnotationMap != null) {