Browse Source

AnnotationAttributesReadingVisitor defensively handles meta-annotation retrieval failure

Issue: SPR-12493
(cherry picked from commit 5018889)
pull/710/head
Juergen Hoeller 11 years ago
parent
commit
dfc79721cb
  1. 3
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
  2. 10
      spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java

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

@ -127,7 +127,8 @@ public abstract class AnnotationUtils { @@ -127,7 +127,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) {

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

@ -26,6 +26,7 @@ import java.util.Set; @@ -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 @@ -72,9 +73,12 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
attributes.add(0, this.attributes);
}
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
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) {

Loading…
Cancel
Save