Closed
Description
Friedrich Messner opened SPR-9453 and commented
We're using Spring's BeanWrapper to access a bean via reflection. For one bean's property
- which has a generic type
- which is read-only (no setter)
- whose getter implements an interface
we're getting a org.springframework.beans.NotReadablePropertyException
since Spring 3.1. I tracked it a little bit and found out that it is related to the ExtendedBeanInfo
class introduced with Spring 3.1. The following example demonstrates this:
package org.springframework.beans;
import static org.junit.Assert.assertEquals;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import org.junit.Test;
public class BeanInfoTest {
public interface Interface<T> {
T getProp();
}
public final class Bean implements Interface<Class<?>> {
private Class<?> prop;
public Class<?> getProp() { return prop; }
}
@Test
public void testWithPlainBeanInfo() throws IntrospectionException {
BeanInfo info = Introspector.getBeanInfo(Bean.class);
assertEquals(2, info.getPropertyDescriptors().length);
}
@Test
public void testWithExtendedBeanInfo() throws IntrospectionException {
ExtendedBeanInfo extendedInfo = new ExtendedBeanInfo(
Introspector.getBeanInfo(Bean.class));
assertEquals(2, extendedInfo.getPropertyDescriptors().length);
}
}
While the first test passes, the second fails on IBM JVM 1.6.
If we do any of
- add a setter
- remove the interface
- change the type to non-generic (e.g. String)
- run it under Sun JVM 1.6
it works.
It seems that ExtendedBeanInfo has a problem with the covariant return types coming from the bridge method for the generic property.
Affects: 3.1.1
Attachments:
- introspect.tgz (1.74 kB)
Issue Links:
- ExtendedBeanInfo exception - java.beans.IntrospectionException [SPR-9702] #14336 ExtendedBeanInfo exception - java.beans.IntrospectionException ("is duplicated by")
- Overhaul non-void JavaBean write method support [SPR-10029] #14663 Overhaul non-void JavaBean write method support
Referenced from: commits b50bb50, 0ee1256, 30d0bd3, 4a8be69
1 votes, 5 watchers