diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index aeb98114eac..c863ab00973 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -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); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java index 942c14a4db3..9d18e7a0ec9 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java @@ -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);