@@ -332,9 +332,13 @@ public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement elem
332332 Assert .notNull (annotationType , "annotationType must not be null" );
333333
334334 // Shortcut: directly present on the element, with no merging needed?
335- A annotation = element .getAnnotation (annotationType );
336- if (annotation != null ) {
337- return AnnotationUtils .synthesizeAnnotation (annotation , element );
335+ if (!(element instanceof Class )) {
336+ // Do not use this shortcut against a Class: Inherited annotations
337+ // would get preferred over locally declared composed annotations.
338+ A annotation = element .getAnnotation (annotationType );
339+ if (annotation != null ) {
340+ return AnnotationUtils .synthesizeAnnotation (annotation , element );
341+ }
338342 }
339343
340344 // Exhaustive retrieval of merged annotation attributes...
@@ -478,9 +482,13 @@ public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement ele
478482 Assert .notNull (annotationType , "annotationType must not be null" );
479483
480484 // Shortcut: directly present on the element, with no merging needed?
481- A annotation = element .getDeclaredAnnotation (annotationType );
482- if (annotation != null ) {
483- return AnnotationUtils .synthesizeAnnotation (annotation , element );
485+ if (!(element instanceof Class )) {
486+ // Do not use this shortcut against a Class: Inherited annotations
487+ // would get preferred over locally declared composed annotations.
488+ A annotation = element .getAnnotation (annotationType );
489+ if (annotation != null ) {
490+ return AnnotationUtils .synthesizeAnnotation (annotation , element );
491+ }
484492 }
485493
486494 // Exhaustive retrieval of merged annotation attributes...
0 commit comments