Closed
Description
Stevo Slavić opened SPR-9007 and commented
ExtendedBeanInfoTests.reproSpr8522 and some other tests fail when run with Java 7 (openjdk & oracle).
[junit] Testcase: reproSpr8522(org.springframework.beans.ExtendedBeanInfoTests): FAILED
[junit]
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] junit.framework.AssertionFailedError:
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] at org.springframework.beans.ExtendedBeanInfoTests.reproSpr8522(ExtendedBeanInfoTests.java:553)
[junit]
[junit]
[junit] Testcase: indexedReadAndNonStandardIndexedWrite(org.springframework.beans.ExtendedBeanInfoTests): FAILED
[junit]
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] junit.framework.AssertionFailedError:
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] at org.springframework.beans.ExtendedBeanInfoTests.indexedReadAndNonStandardIndexedWrite(ExtendedBeanInfoTests.java:436)
[junit]
[junit]
[junit] Testcase: indexedReadAndNonStandardWriteAndNonStandardIndexedWrite(org.springframework.beans.ExtendedBeanInfoTests): FAILED
[junit]
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] junit.framework.AssertionFailedError:
[junit] Expected: is <true>
[junit] got: <false>
[junit]
[junit] at org.springframework.beans.ExtendedBeanInfoTests.indexedReadAndNonStandardWriteAndNonStandardIndexedWrite(ExtendedBeanInfoTests.java:459)
Tests pass when run using Java 6 (openjdk). Looking at the source of Introspector, in getTargetPropertyInfo at least following has been changed:
from
} else if (argCount == 2) {
if (argTypes[0] == int.class && name.startsWith(SET_PREFIX)) {
pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, null, method);
if (throwsException(method, PropertyVetoException.class)) {
pd.setConstrained(true);
}
}
}
to
} else if (argCount == 2) {
if (void.class.equals(resultType) && int.class.equals(argTypes[0]) && name.startsWith(SET_PREFIX)) {
pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, null, method);
if (throwsException(method, PropertyVetoException.class)) {
pd.setConstrained(true);
}
}
}
It seems that non-standard indexed write methods like
public Object setFoos(int i, String foo) { return new Object(); }
are no longer supported - method has to return void.
After changing these setters to return void, tests would pass on both Java 6 and Java 7.
Affects: 3.1 GA
Issue Links:
- Overhaul non-void JavaBean write method support [SPR-10029] #14663 Overhaul non-void JavaBean write method support