You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bean Introspection problem under IBM Java 1.6 with new ExtendedBeanInfo [SPR-9453] #14088
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.
Thanks, Friedrich. I'll need to get an IBM JDK 6 environment up and running to validate / fix this. If, in the meantime, you're feeling ambitious and would like to attempt a fix yourself, it would be more than welcome! See the contributor guidelines for details.
I see the exact same behavior while using the Oracle 1.7 JDK versus the Oracle 1.6 JDK (OS X and Linux). A generic read-only property isn't seen by the extended bean info. The 'normal' bean info finds the property as expected.
The difference is in the output of the ClassUtils.getMostSpecificMethod
While running 1.6: returns a method with a interface return type, this matches the method ExtendedBeanInfo is searching for -> success
While running 1.7: returns a method with the concrete object return type, no match with the method to search -> property not added and thus not found
I think this is the same issue, but I don't have a IBM JDK 6 to test.
The reason that ClassUtils.getMostSpecificMethod is producing different output appears to be that it is receiving different input. In the above example {Introspector.getBeanInfo} the method with the concrete object return type.
The constructor PropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) which is used by Introspector.processPropertyDescriptors() to merge PropertyDesriptor s has changed between JDK 1.6.0 and JDK 1.7.0
// Figure out the merged read method.
Method xr = x.getReadMethod();
Method yr = y.getReadMethod();
// Normally give priority to y's readMethod.
try {
if (yr != null && yr.getDeclaringClass() == getClass0()) {
setReadMethod(yr);
} else {
setReadMethod(xr);
}
} catch (IntrospectionException ex) {
// fall through
}
// Figure out the merged read method.
Method xr = x.getReadMethod();
Method yr = y.getReadMethod();
// Normally give priority to y's readMethod.
try {
if (isAssignable(xr, yr)) {
setReadMethod(yr);
} else {
setReadMethod(xr);
}
} catch (IntrospectionException ex) {
// fall through
}
The result is that the MethodDescriptor refers to public java.lang.Object org.springframework.beans.BeanInfoTest$Bean.getProp() and the PropertyDescriptor refers to public java.lang.Class org.springframework.beans.BeanInfoTest$Bean.getProp() in the above example. Thus, the property isn't added in the ExtendedBeanInfo constructor.
This issue is now resolved with the commit shown below.
More importantly, with the completion of #14357ExtendedBeanInfo is now no longer part of the default code path, meaning that even though this regression has been fixed, it would no longer be encountered anyway. Note that #14357 applies only to 3.2 and beyond, whereas the specific fix addressed by this issue will be backported to 3.1.x with #14412.
commit b50bb5071ac353e77e9d38c72f888de3add923b2
Author: Chris Beams <[email protected]>
Commit: Chris Beams <[email protected]>
Address various ExtendedBeanInfo bugs
- Ensure that ExtendedBeanInfoTests succeeds when building under JDK 7
- Improve handling of read and write method registration where
generic interfaces are involved, per SPR-9453
- Add repro test for SPR-9702, in which EBI fails to register
an indexed read method under certain circumstances
Issue: SPR-9702, SPR-9414, SPR-9453
A general note to watchers of ExtendedBeanInfo-related issues: #14663 is a major refactoring of ExtendedBeanInfo and overall support for non-void returning setter methods.
If you have submitted a reproduction project with this issue, we have run it through its paces against these new changes, but we would like to ask you to do the same against your actual applications.
Please consider updating your dev or test builds to work against 3.1.4.BUILD-SNAPSHOT and/or 3.2.0.BUILD-SNAPSHOT to verify, and we would appreciate any feedback, even if it's to let us know that all is well. So that we can consolidate feedback, please add your comments to #14663, and mention the original issue(s) that you were watching.
Thanks!
Note also that testing against 3.1.4 is preferable to 3.2.0 because ExtendedBeanInfo is always in the code path in the latter, while in 3.2.0 we've optimized things such that ExtendedBeanInfo is only in play for bean classes that have one or more non-void returning setter methods.
Activity
spring-projects-issues commentedon May 30, 2012
Friedrich Messner commented
Just to clarify: with "generic property" I refer to the <T> in the interface and not to the <?> in the subclass property.
spring-projects-issues commentedon Jun 4, 2012
Chris Beams commented
Thanks, Friedrich. I'll need to get an IBM JDK 6 environment up and running to validate / fix this. If, in the meantime, you're feeling ambitious and would like to attempt a fix yourself, it would be more than welcome! See the contributor guidelines for details.
spring-projects-issues commentedon Jul 3, 2012
Dries Schulten commented
I see the exact same behavior while using the Oracle 1.7 JDK versus the Oracle 1.6 JDK (OS X and Linux). A generic read-only property isn't seen by the extended bean info. The 'normal' bean info finds the property as expected.
The difference is in the output of the
ClassUtils.getMostSpecificMethodWhile running 1.6: returns a method with a interface return type, this matches the method ExtendedBeanInfo is searching for -> success
While running 1.7: returns a method with the concrete object return type, no match with the method to search -> property not added and thus not found
I think this is the same issue, but I don't have a IBM JDK 6 to test.
Attaching a simple Maven test project.
spring-projects-issues commentedon Jul 3, 2012
Chris Beams commented
Thanks, Dries.
spring-projects-issues commentedon Aug 15, 2012
Donnchadh O Donnabhain commented
I'm seeing a similar problem with Sun JDK 1.7.0_u6 on OS X and Spring 3.1.2. It seems to be fine with JDK 1.6.
spring-projects-issues commentedon Aug 15, 2012
Donnchadh O Donnabhain commented
The reason that
ClassUtils.getMostSpecificMethodis producing different output appears to be that it is receiving different input. In the above example {Introspector.getBeanInfo} the method with the concrete object return type.spring-projects-issues commentedon Aug 15, 2012
Donnchadh O Donnabhain commented
The constructor
PropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y)which is used byIntrospector.processPropertyDescriptors()to mergePropertyDesriptors has changed between JDK 1.6.0 and JDK 1.7.0The result is that the
MethodDescriptorrefers topublic java.lang.Object org.springframework.beans.BeanInfoTest$Bean.getProp()and thePropertyDescriptorrefers topublic java.lang.Class org.springframework.beans.BeanInfoTest$Bean.getProp()in the above example. Thus, the property isn't added in theExtendedBeanInfoconstructor.spring-projects-issues commentedon Aug 15, 2012
Chris Beams commented
Thanks for the detail, Donnchadh. This should help quite a bit.
spring-projects-issues commentedon Aug 19, 2012
Chris Beams commented
See also the repro project submitted in association with #14336 (which has now been resolved as a duplicate of this issue).
spring-projects-issues commentedon Aug 22, 2012
Chris Beams commented
See additional comments at #14336.
spring-projects-issues commentedon Sep 9, 2012
Chris Beams commented
This issue is now resolved with the commit shown below.
More importantly, with the completion of #14357
ExtendedBeanInfois now no longer part of the default code path, meaning that even though this regression has been fixed, it would no longer be encountered anyway. Note that #14357 applies only to 3.2 and beyond, whereas the specific fix addressed by this issue will be backported to 3.1.x with #14412.spring-projects-issues commentedon Nov 25, 2012
Chris Beams commented
A general note to watchers of
ExtendedBeanInfo-related issues: #14663 is a major refactoring ofExtendedBeanInfoand overall support for non-void returning setter methods.If you have submitted a reproduction project with this issue, we have run it through its paces against these new changes, but we would like to ask you to do the same against your actual applications.
Please consider updating your dev or test builds to work against 3.1.4.BUILD-SNAPSHOT and/or 3.2.0.BUILD-SNAPSHOT to verify, and we would appreciate any feedback, even if it's to let us know that all is well. So that we can consolidate feedback, please add your comments to #14663, and mention the original issue(s) that you were watching.
Thanks!
Note also that testing against 3.1.4 is preferable to 3.2.0 because
ExtendedBeanInfois always in the code path in the latter, while in 3.2.0 we've optimized things such thatExtendedBeanInfois only in play for bean classes that have one or more non-void returning setter methods.