Skip to content

Commit d78e27f

Browse files
committed
Avoid repeated superclass introspection in findAnnotation(Method,...)
Issue: SPR-16730
1 parent 568a0b5 commit d78e27f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,18 @@ public static <A extends Annotation> A findAnnotation(Method method, @Nullable C
555555
if (clazz == null || Object.class == clazz) {
556556
break;
557557
}
558-
try {
559-
Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
560-
Method resolvedEquivalentMethod = BridgeMethodResolver.findBridgedMethod(equivalentMethod);
561-
result = findAnnotation((AnnotatedElement) resolvedEquivalentMethod, annotationType);
562-
}
563-
catch (NoSuchMethodException ex) {
564-
// No equivalent method found
558+
Set<Method> annotatedMethods = getAnnotatedMethodsInBaseType(clazz);
559+
if (!annotatedMethods.isEmpty()) {
560+
for (Method annotatedMethod : annotatedMethods) {
561+
if (annotatedMethod.getName().equals(method.getName()) &&
562+
Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())) {
563+
Method resolvedSuperMethod = BridgeMethodResolver.findBridgedMethod(annotatedMethod);
564+
result = findAnnotation((AnnotatedElement) resolvedSuperMethod, annotationType);
565+
if (result != null) {
566+
break;
567+
}
568+
}
569+
}
565570
}
566571
if (result == null) {
567572
result = searchOnInterfaces(method, annotationType, clazz.getInterfaces());

0 commit comments

Comments
 (0)