Browse Source

Fix ExtendedBeanInfo indexed write method edge case

See comments at ExtendedBeanInfo#reproSpr8522

Issue: SPR-8522
pull/7/head
Chris Beams 15 years ago
parent
commit
71984b8038
  1. 4
      org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java
  2. 28
      org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java

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

@ -227,7 +227,9 @@ public class ExtendedBeanInfo implements BeanInfo { @@ -227,7 +227,9 @@ public class ExtendedBeanInfo implements BeanInfo {
}
// update the existing descriptor's indexed read method
try {
existingIPD.setIndexedReadMethod(indexedReadMethod);
if (indexedReadMethod != null) {
existingIPD.setIndexedReadMethod(indexedReadMethod);
}
} catch (IntrospectionException ex) {
// there is a conflicting indexed setter method present -> null it out and try again
existingIPD.setIndexedWriteMethod(null);

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

@ -499,6 +499,34 @@ public class ExtendedBeanInfoTests { @@ -499,6 +499,34 @@ public class ExtendedBeanInfoTests {
assertThat(ebi.getPropertyDescriptors(), equalTo(bi.getPropertyDescriptors()));
}
/**
* Corners the bug revealed by SPR-8522, in which an (apparently) indexed write method
* without a corresponding indexed read method would fail to be processed correctly by
* ExtendedBeanInfo. The local class C below represents the relevant methods from
* Google's GsonBuilder class. Interestingly, the setDateFormat(int, int) method was
* not actually intended to serve as an indexed write method; it just appears that way.
*/
@Test
public void reproSpr8522() throws IntrospectionException {
@SuppressWarnings("unused") class C {
public Object setDateFormat(String pattern) { return new Object(); }
public Object setDateFormat(int style) { return new Object(); }
public Object setDateFormat(int dateStyle, int timeStyle) { return new Object(); }
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasWriteMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(true));
assertThat(hasReadMethodForProperty(ebi, "dateFormat"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "dateFormat"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "dateFormat"), is(false));
assertThat(hasIndexedWriteMethodForProperty(ebi, "dateFormat"), is(true));
}
@Test
public void propertyCountsMatch() throws IntrospectionException {
BeanInfo bi = Introspector.getBeanInfo(TestBean.class);

Loading…
Cancel
Save