Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Feb 20, 2009 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 20, 2009

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

@spring-projects-issues
Copy link
Collaborator Author

Geir H. Pettersen commented

Demonstration of bug in junit with maven.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants