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 05afe9e368d..5393f6849f0 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 4af65e9cf9e..6937e811e48 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) {