Skip to content

Commit 247843c

Browse files
committed
HHH-19229 Faster checks in ReflectHelper
1 parent 6141168 commit 247843c

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.lang.reflect.TypeVariable;
1616
import java.lang.reflect.WildcardType;
1717
import java.util.Locale;
18+
import java.util.Objects;
1819
import java.util.function.Supplier;
1920

2021
import org.hibernate.AssertionFailure;
@@ -573,16 +574,15 @@ public static void verifyNoIsVariantExists(
573574
Method getMethod,
574575
String stemName) {
575576
// 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 );
577+
for ( Method declaredMethod : containerClass.getDeclaredMethods() ) {
578+
if ( declaredMethod.getParameterCount() == 0
579+
&& !Modifier.isStatic( declaredMethod.getModifiers() )
580+
&& declaredMethod.getName().startsWith("is")
581+
&& declaredMethod.getName().regionMatches(0, stemName, 0, stemName.length() )
582+
&& declaredMethod.getAnnotation( Transient.class ) == null ) {
583+
checkGetAndIsVariants( containerClass, propertyName, getMethod, declaredMethod );
582584
}
583585
}
584-
catch (NoSuchMethodException ignore) {
585-
}
586586
}
587587

588588

@@ -613,17 +613,15 @@ public static void verifyNoGetVariantExists(
613613
Method isMethod,
614614
String stemName) {
615615
// 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 );
616+
for ( Method declaredMethod : containerClass.getDeclaredMethods() ) {
617+
if ( declaredMethod.getParameterCount() == 0
618+
&& !Modifier.isStatic( declaredMethod.getModifiers() )
619+
&& declaredMethod.getName().startsWith("is")
620+
&& declaredMethod.getName().regionMatches(0, stemName, 0, stemName.length() )
621+
&& declaredMethod.getAnnotation( Transient.class ) == null ) {
622+
checkGetAndIsVariants( containerClass, propertyName, declaredMethod, isMethod );
623623
}
624624
}
625-
catch (NoSuchMethodException ignore) {
626-
}
627625
}
628626

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

0 commit comments

Comments
 (0)