Issue 1:
Endrédi, Balázs opened SPR-5569 and commented

Bean definition:

<bean id="test" singleton="false" class="java.lang.String">

<constructor-arg>

<value>test</value>

</constructor-arg>

</bean>

code:

Object stringBean1 = ctx.getBean("test")

Object stringBean2 = ctx.getBean("test")

The first reading of the bean is ok.

The second reading fails because the system interprets the bean as java.lang.StringBuilder.

Affects: 2.0.4, 3.0 M2

Attachments:

StringBean_Mail_Eberhard_Wolff.pdf (78.06 kB)

TestCaseStringBean.jar (3.91 kB)

Issue Links:

#11744 IllegalArgumentException thrown for simple java.lang.String prototype bean ("duplicates")

Issue 2:
diwakar opened SPR-7084 and commented

Code

import org.springframework.context.support.GenericApplicationContext;

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

import org.springframework.core.io.ClassPathResource;

/**

*/

public class IllegalArgumentProblem {

public static void main(String[] args) {
GenericApplicationContext parent = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(parent);
reader.loadBeanDefinitions(new ClassPathResource("app.xml", IllegalArgumentProblem.class));
parent.refresh();

String bean = (String) parent.getBean("x");
String bean2 = (String) parent.getBean("x"); // second access throws the exception.
}

}

Configuration

<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-2.5.xsd">

<bean id="x" class="java.lang.String" scope="prototype">
<constructor-arg><value>PARENT value</value></constructor-arg>
</bean>

</beans>

Error

log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).

log4j:WARN Please initialize the log4j system properly.

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'x' defined in class path resource [app.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:823)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

at java.security.AccessController.doPrivileged(Native Method)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)

at IllegalArgumentProblem.main(IllegalArgumentProblem.java:21)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111)

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)

... 16 more

Caused by: java.lang.IllegalArgumentException: argument type mismatch

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)

... 18 more

Process finished with exit code 1

Affects: 2.5.5, 2.5.6

Issue Links:

#10240 not singleton StringBeans ("is duplicated by")

Referenced from: commits 12ce250