Skip to content

Commit 0cc6a9e

Browse files
committed
Avoid getDeclaredMethod check in ReflectionUtils.isObjectMethod
Closes gh-22730
1 parent 9ea02c6 commit 0cc6a9e

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,8 @@ public static boolean isToStringMethod(@Nullable Method method) {
558558
* Determine whether the given method is originally declared by {@link java.lang.Object}.
559559
*/
560560
public static boolean isObjectMethod(@Nullable Method method) {
561-
if (method == null) {
562-
return false;
563-
}
564-
try {
565-
Object.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
566-
return true;
567-
}
568-
catch (Exception ex) {
569-
return false;
570-
}
561+
return (method != null && (method.getDeclaringClass() == Object.class ||
562+
isEqualsMethod(method) || isHashCodeMethod(method) || isToStringMethod(method)));
571563
}
572564

573565
/**

0 commit comments

Comments
 (0)