Fix regression in static setter method support
The intention of ExtendedBeanInfo, introduced with SPR-8079 in v3.1.0.M2, was to support dependency injection against non-void returning write methods. However, it also inadvertently introduced support for injection against static setter methods. When use of ExtendedBeanInfo was made optional with SPR-9723 in v3.2.0.M2, ExtendedBeanInfo continued to support static write methods, but its new BeanInfoFactory-based approach to testing whether or not a given bean class contains candidate write methods was written in a fashion exclusive of static methods, and this thereby introduced a regression - a regression in an otherwise undocumented and unintended feature, but a regression nevertheless. The reporting of SPR-10115 proves that at least one user has come to depend on this behavior allowing injection against static write methods, and so this commit fixes the regression by ensuring that the candidacy test includes standard and non-void setter methods having a static modifier. Issue: SPR-10115, SPR-9723, SPR-8079
This commit is contained in:
@@ -1550,6 +1550,24 @@ public final class BeanWrapperTests {
|
||||
assertEquals(TestEnum.TEST_VALUE, consumer.getEnumValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cornerSpr10115() {
|
||||
Spr10115Bean foo = new Spr10115Bean();
|
||||
BeanWrapperImpl bwi = new BeanWrapperImpl();
|
||||
bwi.setWrappedInstance(foo);
|
||||
bwi.setPropertyValue("prop1", "val1");
|
||||
assertEquals("val1", Spr10115Bean.prop1);
|
||||
}
|
||||
|
||||
|
||||
static class Spr10115Bean {
|
||||
private static String prop1;
|
||||
|
||||
public static void setProp1(String prop1) {
|
||||
Spr10115Bean.prop1 = prop1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Foo {
|
||||
|
||||
|
||||
@@ -946,4 +946,28 @@ public class ExtendedBeanInfoTests {
|
||||
assertThat(hasIndexedWriteMethodForProperty(bi, "address"), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSupportStaticWriteMethod() throws IntrospectionException {
|
||||
{
|
||||
BeanInfo bi = Introspector.getBeanInfo(WithStaticWriteMethod.class);
|
||||
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
|
||||
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(false));
|
||||
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
|
||||
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
|
||||
}
|
||||
{
|
||||
BeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(WithStaticWriteMethod.class));
|
||||
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
|
||||
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(true));
|
||||
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
|
||||
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
|
||||
}
|
||||
}
|
||||
|
||||
static class WithStaticWriteMethod {
|
||||
@SuppressWarnings("unused")
|
||||
public static void setProp1(String prop1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user