@@ -698,17 +698,31 @@ class LawLibrary extends Library implements TextBookOperations {
698
698
}
699
699
700
700
701
- /**
702
- * java.beans.Introspector returns the "wrong" declaring class for overridden read
703
- * methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
704
- * method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
705
- * helps out here, and is now put into use in ExtendedBeanInfo as well
706
- */
707
701
@ Test
708
- public void demonstrateCauseSpr8949 () throws IntrospectionException {
709
- BeanInfo info = Introspector .getBeanInfo (B .class );
702
+ public void cornerSpr8949 () throws IntrospectionException {
703
+ class A {
704
+ @ SuppressWarnings ("unused" )
705
+ public boolean isTargetMethod () {
706
+ return false ;
707
+ }
708
+ }
710
709
711
- for (PropertyDescriptor pd : info .getPropertyDescriptors ()) {
710
+ class B extends A {
711
+ @ Override
712
+ public boolean isTargetMethod () {
713
+ return false ;
714
+ }
715
+ }
716
+
717
+ BeanInfo bi = Introspector .getBeanInfo (B .class );
718
+
719
+ /* first, demonstrate the 'problem':
720
+ * java.beans.Introspector returns the "wrong" declaring class for overridden read
721
+ * methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
722
+ * method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
723
+ * helps out here, and is now put into use in ExtendedBeanInfo as well
724
+ */
725
+ for (PropertyDescriptor pd : bi .getPropertyDescriptors ()) {
712
726
if ("targetMethod" .equals (pd .getName ())) {
713
727
Method readMethod = pd .getReadMethod ();
714
728
assertTrue (readMethod .getDeclaringClass ().equals (A .class )); // we expected B!
@@ -717,11 +731,8 @@ public void demonstrateCauseSpr8949() throws IntrospectionException {
717
731
assertTrue (msReadMethod .getDeclaringClass ().equals (B .class )); // and now we get it.
718
732
}
719
733
}
720
- }
721
734
722
- @ Test
723
- public void cornerSpr8949 () throws IntrospectionException {
724
- BeanInfo bi = Introspector .getBeanInfo (B .class );
735
+ // and now demonstrate that we've indeed fixed the problem
725
736
ExtendedBeanInfo ebi = new ExtendedBeanInfo (bi );
726
737
727
738
assertThat (hasReadMethodForProperty (bi , "targetMethod" ), is (true ));
@@ -731,13 +742,13 @@ public void cornerSpr8949() throws IntrospectionException {
731
742
assertThat (hasWriteMethodForProperty (ebi , "targetMethod" ), is (false ));
732
743
}
733
744
734
- static class A {
745
+ static class X {
735
746
public boolean isTargetMethod () {
736
747
return false ;
737
748
}
738
749
}
739
750
740
- static class B extends A {
751
+ static class Y extends X {
741
752
@ Override
742
753
public boolean isTargetMethod () {
743
754
return false ;
0 commit comments