Skip to content

Commit ef143d3

Browse files
committed
Polish ExtendedBeanInfo and tests
ExtendedBeanInfo - Reduce log messages from warn to debug - Remove now-incorrect comment indicating underlying property descriptors are never modified (they actually are as of SPR-8806) ExtendedBeanInfoTests - Consolidate SPR-8949 tests - Eliminate compiler warnings Issue: SPR-8949, SPR-8806
1 parent e25f1cb commit ef143d3

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ class ExtendedBeanInfo implements BeanInfo {
7575
public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
7676
this.delegate = delegate;
7777

78-
// PropertyDescriptor instances from the delegate object are never added directly, but always
79-
// copied to the local collection of #propertyDescriptors and returned by calls to
80-
// #getPropertyDescriptors(). this algorithm iterates through all methods (method descriptors)
81-
// in the wrapped BeanInfo object, copying any existing PropertyDescriptor or creating a new
82-
// one for any non-standard setter methods found.
83-
8478
ALL_METHODS:
8579
for (MethodDescriptor md : delegate.getMethodDescriptors()) {
8680
Method method = md.getMethod();
@@ -282,7 +276,7 @@ private void addOrUpdatePropertyDescriptor(PropertyDescriptor pd, String propert
282276
}
283277
this.propertyDescriptors.add(pd);
284278
} catch (IntrospectionException ex) {
285-
logger.warn(format("Could not create new PropertyDescriptor for readMethod [%s] writeMethod [%s] " +
279+
logger.debug(format("Could not create new PropertyDescriptor for readMethod [%s] writeMethod [%s] " +
286280
"indexedReadMethod [%s] indexedWriteMethod [%s] for property [%s]. Reason: %s",
287281
readMethod, writeMethod, indexedReadMethod, indexedWriteMethod, propertyName, ex.getMessage()));
288282
// suppress exception and attempt to continue
@@ -293,7 +287,7 @@ private void addOrUpdatePropertyDescriptor(PropertyDescriptor pd, String propert
293287
try {
294288
pd.setWriteMethod(writeMethod);
295289
} catch (IntrospectionException ex) {
296-
logger.warn(format("Could not add write method [%s] for property [%s]. Reason: %s",
290+
logger.debug(format("Could not add write method [%s] for property [%s]. Reason: %s",
297291
writeMethod, propertyName, ex.getMessage()));
298292
// fall through -> add property descriptor as best we can
299293
}

org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java

+26-15
Original file line numberDiff line numberDiff line change
@@ -698,17 +698,31 @@ class LawLibrary extends Library implements TextBookOperations {
698698
}
699699

700700

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-
*/
707701
@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+
}
710709

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()) {
712726
if ("targetMethod".equals(pd.getName())) {
713727
Method readMethod = pd.getReadMethod();
714728
assertTrue(readMethod.getDeclaringClass().equals(A.class)); // we expected B!
@@ -717,11 +731,8 @@ public void demonstrateCauseSpr8949() throws IntrospectionException {
717731
assertTrue(msReadMethod.getDeclaringClass().equals(B.class)); // and now we get it.
718732
}
719733
}
720-
}
721734

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
725736
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
726737

727738
assertThat(hasReadMethodForProperty(bi, "targetMethod"), is(true));
@@ -731,13 +742,13 @@ public void cornerSpr8949() throws IntrospectionException {
731742
assertThat(hasWriteMethodForProperty(ebi, "targetMethod"), is(false));
732743
}
733744

734-
static class A {
745+
static class X {
735746
public boolean isTargetMethod() {
736747
return false;
737748
}
738749
}
739750

740-
static class B extends A {
751+
static class Y extends X {
741752
@Override
742753
public boolean isTargetMethod() {
743754
return false;

0 commit comments

Comments
 (0)