Skip to content

Commit 2a0d68c

Browse files
committed
restored getMostSpecificMethod's traversal of the inheritance hierarchy
1 parent fd81aa2 commit 2a0d68c

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -689,18 +689,12 @@ public static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName
689689
* <code>targetClass</code> doesn't implement it or is <code>null</code>
690690
*/
691691
public static Method getMostSpecificMethod(Method method, Class targetClass) {
692-
Method result = method;
692+
Method specificMethod = null;
693693
if (method != null && !Modifier.isPrivate(method.getModifiers()) &&
694694
targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
695-
try {
696-
result = targetClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
697-
}
698-
catch (NoSuchMethodException ex) {
699-
// Perhaps the target class doesn't implement this method:
700-
// that's fine, just use the original method.
701-
}
695+
specificMethod = ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
702696
}
703-
return result;
697+
return (specificMethod != null ? specificMethod : method);
704698
}
705699

706700
/**
@@ -716,14 +710,11 @@ public static Method getStaticMethod(Class clazz, String methodName, Class... ar
716710
Assert.notNull(methodName, "Method name must not be null");
717711
try {
718712
Method method = clazz.getDeclaredMethod(methodName, args);
719-
if ((method.getModifiers() & Modifier.STATIC) != 0) {
720-
return method;
721-
}
713+
return ((method.getModifiers() & Modifier.STATIC) != 0 ? method : null);
722714
}
723715
catch (NoSuchMethodException ex) {
724716
return null;
725717
}
726-
return null;
727718
}
728719

729720

org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ public class HandlerMethodResolver {
7272
*/
7373
public void init(Class<?> handlerType) {
7474
Class<?>[] handlerTypes =
75-
Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class<?>[]{handlerType};
75+
Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class<?>[] {handlerType};
7676
for (final Class<?> currentHandlerType : handlerTypes) {
7777
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
7878
public void doWith(Method method) {
79-
if (isHandlerMethod(ClassUtils.getMostSpecificMethod(method, currentHandlerType))) {
80-
handlerMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType));
79+
Method specificMethod = ClassUtils.getMostSpecificMethod(method, currentHandlerType);
80+
if (isHandlerMethod(specificMethod)) {
81+
handlerMethods.add(specificMethod);
8182
}
8283
else if (method.isAnnotationPresent(InitBinder.class)) {
83-
initBinderMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType));
84+
initBinderMethods.add(specificMethod);
8485
}
8586
else if (method.isAnnotationPresent(ModelAttribute.class)) {
86-
modelAttributeMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType));
87+
modelAttributeMethods.add(specificMethod);
8788
}
8889
}
8990
});

0 commit comments

Comments
 (0)