Skip to content

Buggy reuse of list in prototype, when using shorthand definition in xml. [SPR-5512] #10184

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

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>

Affects: 2.5.6

Attachments:

Referenced from: commits dc1edcc

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions