Skip to content

Commit 717358b

Browse files
committed
Short circuit ClassUtils.findPubliclyAccessibleMethodIfPossible(...)
Once we find a publicly accessible method, there is no need to continue traversing the type hierarchy. See gh-35556
1 parent 836634c commit 717358b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,6 @@ public static Method getPubliclyAccessibleMethodIfPossible(Method method, @Nulla
15361536
private static Method findPubliclyAccessibleMethodIfPossible(
15371537
String methodName, Class<?>[] parameterTypes, Class<?> declaringClass) {
15381538

1539-
Method result = null;
15401539
Class<?> current = declaringClass.getSuperclass();
15411540
while (current != null) {
15421541
Method method = getMethodOrNull(current, methodName, parameterTypes);
@@ -1546,11 +1545,11 @@ private static Method findPubliclyAccessibleMethodIfPossible(
15461545
if (Modifier.isPublic(method.getDeclaringClass().getModifiers()) &&
15471546
method.getDeclaringClass().getModule().isExported(
15481547
method.getDeclaringClass().getPackageName(), ClassUtils.class.getModule())) {
1549-
result = method;
1548+
return method;
15501549
}
15511550
current = method.getDeclaringClass().getSuperclass();
15521551
}
1553-
return result;
1552+
return null;
15541553
}
15551554

15561555
/**

0 commit comments

Comments
 (0)