Repository navigation
Closed
Closed
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression
Milestone
Description
Stepan Koltsov opened SPR-8432 and commented
Regression in 3.1 M2. When subclass overrides getter with narrower return type, Spring fails to set property.
public class ReadWritePropertyErrorMain {
public static void main(String[] args) {
final String contextXml =
"<beans xmlns='http://www.springframework.org/schema/beans'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xsi:schemaLocation='" +
" http://www.springframework.org/schema/beans" +
" http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" +
" '" +
">" +
" <bean id='t' class='" + MyTemplate5.class.getName() + "'/>" +
" <bean class='" + MyDaoSupport5.class.getName() + "'>" +
" <property name='myTemplate4' ref='t'/>" +
" </bean>" +
"</beans>";
AbstractXmlApplicationContext applicationContext = new AbstractXmlApplicationContext() {
@Override
protected Resource[] getConfigResources() {
return new Resource[] { new ByteArrayResource(contextXml.getBytes()) };
}
};
applicationContext.refresh();
System.out.println("$");
}
}
public class MyDaoSupport4 {
private MyTemplate4 myTemplate4;
public void setMyTemplate4(MyTemplate4 jdbcTemplate4) {
this.myTemplate4 = jdbcTemplate4;
}
public MyTemplate4 getMyTemplate4() {
return myTemplate4;
}
}
public class MyDaoSupport5 extends MyDaoSupport4 {
@Override
public MyTemplate5 getMyTemplate4() { // <-- narrow subtype is here
return (MyTemplate5) super.getMyTemplate4();
}
}
public class MyTemplate4 { }
public class MyTemplate5 extends MyTemplate4 { }
Error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ru.yandex.commune.junk.stepancheg.spring.readWrite.MyDaoSupport5#0' defined in resource loaded from byte array: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Read and write parameter types are not the same
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at ru.yandex.commune.junk.stepancheg.spring.readWrite.ReadWriteProperty.main(ReadWriteProperty.java:36)
Caused by: java.lang.IllegalStateException: Read and write parameter types are not the same
at org.springframework.core.convert.Property.resolveMethodParameter(Property.java:137)
at org.springframework.core.convert.Property.<init>(Property.java:56)
at org.springframework.beans.BeanWrapperImpl.property(BeanWrapperImpl.java:1174)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:497)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 9 more
Affects: 3.1 M2
Attachments:
- mylyn-context.zip (8.61 kB)
Issue Links:
- Overhaul non-void JavaBean write method support [SPR-10029] #14663 Overhaul non-void JavaBean write method support
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression
Activity
spring-projects-issues commentedon Jun 10, 2011
Stepan Koltsov commented
This worked in 3.1 M1.
spring-projects-issues commentedon Jun 12, 2011
Chris Beams commented
This very likely has to do with the introduction of ExtendedBeanInfo in 3.1 M2
spring-projects-issues commentedon Jun 16, 2011
Chris Beams commented
Thanks for catching this, Stepan.
In fact, it did not have to do with the introduction of
ExtendedBeanInfoin Spring 3.1 M2, but rather a different new class, see below.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.