@@ -332,9 +332,13 @@ public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement elem
332
332
Assert .notNull (annotationType , "annotationType must not be null" );
333
333
334
334
// 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
+ }
338
342
}
339
343
340
344
// Exhaustive retrieval of merged annotation attributes...
@@ -478,9 +482,13 @@ public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement ele
478
482
Assert .notNull (annotationType , "annotationType must not be null" );
479
483
480
484
// 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
+ }
484
492
}
485
493
486
494
// Exhaustive retrieval of merged annotation attributes...
0 commit comments