@@ -490,7 +490,8 @@ private static Method getGetterOrNull(Class[] interfaces, String propertyName) {
490
490
}
491
491
492
492
private static Method getGetterOrNull (Class containerClass , String propertyName ) {
493
- for ( Method method : containerClass .getDeclaredMethods () ) {
493
+ Method [] declaredMethods = containerClass .getDeclaredMethods ();
494
+ for ( Method method : declaredMethods ) {
494
495
// if the method has parameters, skip it
495
496
if ( method .getParameterCount () != 0 ) {
496
497
continue ;
@@ -516,7 +517,7 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
516
517
final String stemName = methodName .substring ( 3 );
517
518
final String decapitalizedStemName = Introspector .decapitalize ( stemName );
518
519
if ( stemName .equals ( propertyName ) || decapitalizedStemName .equals ( propertyName ) ) {
519
- verifyNoIsVariantExists ( containerClass , propertyName , method , stemName );
520
+ verifyNoIsVariantExists ( containerClass , propertyName , method , stemName , declaredMethods );
520
521
return method ;
521
522
}
522
523
@@ -527,7 +528,7 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
527
528
final String stemName = methodName .substring ( 2 );
528
529
String decapitalizedStemName = Introspector .decapitalize ( stemName );
529
530
if ( stemName .equals ( propertyName ) || decapitalizedStemName .equals ( propertyName ) ) {
530
- verifyNoGetVariantExists ( containerClass , propertyName , method , stemName );
531
+ verifyNoGetVariantExists ( containerClass , propertyName , method , stemName , declaredMethods );
531
532
return method ;
532
533
}
533
534
}
@@ -536,21 +537,30 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
536
537
return null ;
537
538
}
538
539
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
+
539
549
private static void verifyNoIsVariantExists (
540
550
Class containerClass ,
541
551
String propertyName ,
542
552
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 ;
552
559
}
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 );
554
564
}
555
565
}
556
566
@@ -580,17 +590,15 @@ private static void verifyNoGetVariantExists(
580
590
Class containerClass ,
581
591
String propertyName ,
582
592
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 ;
592
598
}
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 );
594
602
}
595
603
}
596
604
0 commit comments