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
If you are working with a prototype bean that has a list setter, the beanfactory is reusing the list if you use a shorthand creation of the list.
This results in a strange behavior. Any changes you make to the list in a bean created from the prototype will appear on all new versions of the prototype.
Example:
public class SomePrototype {
private List<String> aList = new ArrayList<String>();
public List<String> getAList() {
return aList;
}
public void setAList(List<String> aList) {
this.aList = aList;
}
}
<bean id="buggedPrototype" class="SomePrototype" scope="prototype">
<property name="AList" value="The one and only"/>
</bean>
<bean id="okPrototype" class="SomePrototype" scope="prototype">
<property name="AList">
<list>
<value>The one and only</value>
</list>
</property>
</bean>
Thanks for raising this! Indeed, non-singleton beans need to receive an independent collection/array even when based on a single specified String value. Fixed as of 3.0 M2.
Geir H. Pettersen opened SPR-5512 and commented
If you are working with a prototype bean that has a list setter, the beanfactory is reusing the list if you use a shorthand creation of the list.
This results in a strange behavior. Any changes you make to the list in a bean created from the prototype will appear on all new versions of the prototype.
Example:
Affects: 2.5.6
Attachments:
Referenced from: commits dc1edcc
The text was updated successfully, but these errors were encountered: