Skip to content

Commit 4168f91

Browse files
committed
HHH-19229 Faster checks in ReflectHelper
1 parent 6141168 commit 4168f91

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,15 @@ public static void verifyNoIsVariantExists(
573573
Method getMethod,
574574
String stemName) {
575575
// verify that the Class<?> does not also define a method with the same stem name with 'is'
576-
try {
577-
final Method isMethod = containerClass.getDeclaredMethod( "is" + stemName );
578-
if ( !Modifier.isStatic( isMethod.getModifiers() ) && isMethod.getAnnotation( Transient.class ) == null ) {
579-
// No such method should throw the caught exception. So if we get here, there was
580-
// such a method.
581-
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
576+
for ( Method declaredMethod : containerClass.getDeclaredMethods() ) {
577+
if ( declaredMethod.getParameterCount() == 0
578+
&& !Modifier.isStatic( declaredMethod.getModifiers() )
579+
&& declaredMethod.getName().startsWith("is")
580+
&& declaredMethod.getName().regionMatches(0, stemName, 0, stemName.length() )
581+
&& declaredMethod.getAnnotation( Transient.class ) == null ) {
582+
checkGetAndIsVariants( containerClass, propertyName, getMethod, declaredMethod );
582583
}
583584
}
584-
catch (NoSuchMethodException ignore) {
585-
}
586585
}
587586

588587

@@ -613,17 +612,15 @@ public static void verifyNoGetVariantExists(
613612
Method isMethod,
614613
String stemName) {
615614
// verify that the Class<?> does not also define a method with the same stem name with 'is'
616-
try {
617-
final Method getMethod = containerClass.getDeclaredMethod( "get" + stemName );
618-
// No such method should throw the caught exception. So if we get here, there was
619-
// such a method.
620-
if ( !Modifier.isStatic( getMethod.getModifiers() )
621-
&& getMethod.getAnnotation( Transient.class ) == null ) {
622-
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
615+
for ( Method declaredMethod : containerClass.getDeclaredMethods() ) {
616+
if ( declaredMethod.getParameterCount() == 0
617+
&& !Modifier.isStatic( declaredMethod.getModifiers() )
618+
&& declaredMethod.getName().startsWith("is")
619+
&& declaredMethod.getName().regionMatches(0, stemName, 0, stemName.length() )
620+
&& declaredMethod.getAnnotation( Transient.class ) == null ) {
621+
checkGetAndIsVariants( containerClass, propertyName, declaredMethod, isMethod );
623622
}
624623
}
625-
catch (NoSuchMethodException ignore) {
626-
}
627624
}
628625

629626
public static Method getterMethodOrNull(Class<?> containerJavaType, String propertyName) {

0 commit comments

Comments
 (0)