AnnotationAttributesReadingVisitor defensively handles meta-annotation retrieval failure

Issue: SPR-12493
This commit is contained in:
Juergen Hoeller 2014-12-02 15:12:23 +01:00
parent 1aad4da6b6
commit 5018889d78
2 changed files with 9 additions and 4 deletions

View File

@ -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) {

View File

@ -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,11 +73,14 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
attributes.add(0, this.attributes);
}
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
for (Annotation metaAnnotation : AnnotationUtils.getAnnotations(annotationClass)) {
Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
if (!ObjectUtils.isEmpty(metaAnnotations)) {
for (Annotation metaAnnotation : metaAnnotations) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
}
}
}
if (this.metaAnnotationMap != null) {
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
}