Short circuit ClassUtils.findPubliclyAccessibleMethodIfPossible(...)

Once we find a publicly accessible method, there is no need to continue
traversing the type hierarchy.

See gh-35556
This commit is contained in:
Sam Brannen 2025-10-02 11:44:54 +02:00
parent 836634c47f
commit 717358b56b
1 changed files with 2 additions and 3 deletions

View File

@ -1536,7 +1536,6 @@ public abstract class ClassUtils {
private static Method findPubliclyAccessibleMethodIfPossible(
String methodName, Class<?>[] parameterTypes, Class<?> declaringClass) {
Method result = null;
Class<?> current = declaringClass.getSuperclass();
while (current != null) {
Method method = getMethodOrNull(current, methodName, parameterTypes);
@ -1546,11 +1545,11 @@ public abstract class ClassUtils {
if (Modifier.isPublic(method.getDeclaringClass().getModifiers()) &&
method.getDeclaringClass().getModule().isExported(
method.getDeclaringClass().getPackageName(), ClassUtils.class.getModule())) {
result = method;
return method;
}
current = method.getDeclaringClass().getSuperclass();
}
return result;
return null;
}
/**