From d78e27f1e9be6c0aeea293c2be19c706cc6c29cd Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 17 Apr 2018 16:44:28 +0200 Subject: [PATCH] Avoid repeated superclass introspection in findAnnotation(Method,...) Issue: SPR-16730 --- .../core/annotation/AnnotationUtils.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 54b64dbaac..7e534efb38 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -555,13 +555,18 @@ public abstract class AnnotationUtils { if (clazz == null || Object.class == clazz) { break; } - try { - Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); - Method resolvedEquivalentMethod = BridgeMethodResolver.findBridgedMethod(equivalentMethod); - result = findAnnotation((AnnotatedElement) resolvedEquivalentMethod, annotationType); - } - catch (NoSuchMethodException ex) { - // No equivalent method found + Set annotatedMethods = getAnnotatedMethodsInBaseType(clazz); + if (!annotatedMethods.isEmpty()) { + for (Method annotatedMethod : annotatedMethods) { + if (annotatedMethod.getName().equals(method.getName()) && + Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())) { + Method resolvedSuperMethod = BridgeMethodResolver.findBridgedMethod(annotatedMethod); + result = findAnnotation((AnnotatedElement) resolvedSuperMethod, annotationType); + if (result != null) { + break; + } + } + } } if (result == null) { result = searchOnInterfaces(method, annotationType, clazz.getInterfaces());