@@ -490,7 +490,8 @@ private static Method getGetterOrNull(Class[] interfaces, String propertyName) {
490490 }
491491
492492 private static Method getGetterOrNull (Class containerClass , String propertyName ) {
493- for ( Method method : containerClass .getDeclaredMethods () ) {
493+ Method [] declaredMethods = containerClass .getDeclaredMethods ();
494+ for ( Method method : declaredMethods ) {
494495 // if the method has parameters, skip it
495496 if ( method .getParameterCount () != 0 ) {
496497 continue ;
@@ -516,7 +517,7 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
516517 final String stemName = methodName .substring ( 3 );
517518 final String decapitalizedStemName = Introspector .decapitalize ( stemName );
518519 if ( stemName .equals ( propertyName ) || decapitalizedStemName .equals ( propertyName ) ) {
519- verifyNoIsVariantExists ( containerClass , propertyName , method , stemName );
520+ verifyNoIsVariantExists ( containerClass , propertyName , method , stemName , declaredMethods );
520521 return method ;
521522 }
522523
@@ -527,7 +528,7 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
527528 final String stemName = methodName .substring ( 2 );
528529 String decapitalizedStemName = Introspector .decapitalize ( stemName );
529530 if ( stemName .equals ( propertyName ) || decapitalizedStemName .equals ( propertyName ) ) {
530- verifyNoGetVariantExists ( containerClass , propertyName , method , stemName );
531+ verifyNoGetVariantExists ( containerClass , propertyName , method , stemName , declaredMethods );
531532 return method ;
532533 }
533534 }
@@ -536,21 +537,30 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
536537 return null ;
537538 }
538539
540+ private static Method findMethod (String name , Method [] methods ) {
541+ for (Method method : methods ) {
542+ if (method .getName ().equals (name )) {
543+ return method ;
544+ }
545+ }
546+ return null ;
547+ }
548+
539549 private static void verifyNoIsVariantExists (
540550 Class containerClass ,
541551 String propertyName ,
542552 Method getMethod ,
543- String stemName ) {
544- // verify that the Class does not also define a method with the same stem name with 'is'
545- try {
546- final Method isMethod = containerClass .getDeclaredMethod ( "is" + stemName );
547- if ( !Modifier .isStatic ( isMethod .getModifiers () ) && isMethod .getAnnotation ( Transient .class ) == null ) {
548- // No such method should throw the caught exception. So if we get here, there was
549- // such a method.
550- checkGetAndIsVariants ( containerClass , propertyName , getMethod , isMethod );
551- }
553+ String stemName ,
554+ Method [] declaredMethods ) {
555+
556+ Method isMethod = findMethod ("is" + stemName , declaredMethods );
557+ if (isMethod == null ) {
558+ return ;
552559 }
553- catch (NoSuchMethodException ignore ) {
560+
561+ // verify that the Class does not also define a method with the same stem name with 'is'
562+ if ( !Modifier .isStatic ( isMethod .getModifiers () ) && isMethod .getAnnotation ( Transient .class ) == null ) {
563+ checkGetAndIsVariants ( containerClass , propertyName , getMethod , isMethod );
554564 }
555565 }
556566
@@ -580,17 +590,15 @@ private static void verifyNoGetVariantExists(
580590 Class containerClass ,
581591 String propertyName ,
582592 Method isMethod ,
583- String stemName ) {
584- // verify that the Class does not also define a method with the same stem name with 'is'
585- try {
586- final Method getMethod = containerClass .getDeclaredMethod ( "get" + stemName );
587- // No such method should throw the caught exception. So if we get here, there was
588- // such a method.
589- if ( !Modifier .isStatic ( getMethod .getModifiers () ) && getMethod .getAnnotation ( Transient .class ) == null ) {
590- checkGetAndIsVariants ( containerClass , propertyName , getMethod , isMethod );
591- }
593+ String stemName ,
594+ Method [] declaredMethods ) {
595+ Method getMethod = findMethod ("is" + stemName , declaredMethods );
596+ if (isMethod == null ) {
597+ return ;
592598 }
593- catch (NoSuchMethodException ignore ) {
599+ // verify that the Class does not also define a method with the same stem name with 'is'
600+ if ( !Modifier .isStatic ( getMethod .getModifiers () ) && getMethod .getAnnotation ( Transient .class ) == null ) {
601+ checkGetAndIsVariants ( containerClass , propertyName , getMethod , isMethod );
594602 }
595603 }
596604
0 commit comments