From 63115ed6eb9b94a85914c946f851b41a31d528f8 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 23 Mar 2016 19:27:30 +0100 Subject: [PATCH] Do not use annotation detection shortcuts on Class Issue: SPR-13440 --- .../annotation/AnnotatedElementUtils.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index 7cc077fabb..0caaa805e7 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -332,9 +332,13 @@ public class AnnotatedElementUtils { Assert.notNull(annotationType, "annotationType must not be null"); // Shortcut: directly present on the element, with no merging needed? - A annotation = element.getAnnotation(annotationType); - if (annotation != null) { - return AnnotationUtils.synthesizeAnnotation(annotation, element); + if (!(element instanceof Class)) { + // Do not use this shortcut against a Class: Inherited annotations + // would get preferred over locally declared composed annotations. + A annotation = element.getAnnotation(annotationType); + if (annotation != null) { + return AnnotationUtils.synthesizeAnnotation(annotation, element); + } } // Exhaustive retrieval of merged annotation attributes... @@ -478,9 +482,13 @@ public class AnnotatedElementUtils { Assert.notNull(annotationType, "annotationType must not be null"); // Shortcut: directly present on the element, with no merging needed? - A annotation = element.getDeclaredAnnotation(annotationType); - if (annotation != null) { - return AnnotationUtils.synthesizeAnnotation(annotation, element); + if (!(element instanceof Class)) { + // Do not use this shortcut against a Class: Inherited annotations + // would get preferred over locally declared composed annotations. + A annotation = element.getAnnotation(annotationType); + if (annotation != null) { + return AnnotationUtils.synthesizeAnnotation(annotation, element); + } } // Exhaustive retrieval of merged annotation attributes...