Fix ExtendedBeanInfo indexed write method edge case
See comments at ExtendedBeanInfo#reproSpr8522 Issue: SPR-8522
This commit is contained in:
parent
2fc78fb8fd
commit
71984b8038
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue