title: Spring BeanUtils copy properties with a field of List
body: <p>I hava Foo and Item class as below.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public class Foo {
      private Long id;
      private List&lt;Item&gt; items;
  
      public Foo(Long id) {
          this.id = id;
          this.items = new ArrayList&lt;Item&gt;();
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public List&lt;Item&gt; getItems() {
          return items;
      }
  
      public void setItems(List&lt;Item&gt; items) {
          this.items = items;
      }
  }
  
  
  public class Item {
      private String bar;
  
      public Item(String bar) {
          this.bar = bar;
      }
  
      public String getBar() {
          return bar;
      }
  
      public void setBar(String bar) {
          this.bar = bar;
      }
  
      @Override
      public String toString() {
          return "Item{" + "bar='" + bar + '\'' + '}';
      }
  }
  </code></pre>
  
  <p>When I am copying the Foo class using spring BeanUtils the reference for the list field is not changing.</p>
  
  <pre><code>import org.springframework.beans.BeanUtils;
  
  public class SimpleCopyMain {
  
      public static void main(String[] args) {
          Foo foo = new Foo(1L);
          foo.getItems().add(new Item("item1"));
          foo.getItems().add(new Item("item2"));
  
          Foo fooSnapShot = new Foo(100L);
          BeanUtils.copyProperties(foo,fooSnapShot);
  
          foo.setId(999L);
          System.out.println("fooSnapShot id field value is not changing as expected : " + fooSnapShot.getId());
  
          foo.getItems().add(new Item("item3"));
  
          System.out.println("fooSnapShot items value is changing unexpectedly : " + fooSnapShot.getItems());
      }
  }
  </code></pre>
  
  <p>The output for SimpleCopyMain class is below :</p>
  
  <pre><code>fooSnapShot id field value is not changing as expected : 1
  fooSnapShot items value is changing unexpectedly : [Item{bar='item1'}, Item{bar='item2'}, Item{bar='item3'}]
  </code></pre>
  
  <p>However when I create a new instance for the list field and copy the references one by one, I get the behaviour as I expected.</p>
  
  <pre><code>import java.util.ArrayList;
  
  import org.springframework.beans.BeanUtils;
  
  public class CopyMain {
  
      public static void main(String[] args) {
          Foo foo = new Foo(1L);
          foo.getItems().add(new Item("item1"));
          foo.getItems().add(new Item("item2"));
  
          Foo fooSnapShot = new Foo(100L);
          BeanUtils.copyProperties(foo, fooSnapShot);
  
          fooSnapShot.setItems(new ArrayList&lt;Item&gt;(foo.getItems().size()));
          for(int i = 0; i &lt; foo.getItems().size(); i++){
              Item anItem = new Item("");
              BeanUtils.copyProperties(foo.getItems().get(i), anItem);
              fooSnapShot.getItems().add(anItem);
          }
  
          foo.setId(999L);
          System.out.println("fooSnapShot id field value is not changing as expected : " + fooSnapShot.getId());
  
          foo.getItems().add(new Item("item3"));
  
          System.out.println("fooSnapShot items value is is not changing : " + fooSnapShot.getItems());
      }
  }
  </code></pre>
  
  <p>Here is the output :</p>
  
  <pre><code>fooSnapShot id field value is not changing as expected : 1
  fooSnapShot items value is is not changing : [Item{bar='item1'}, Item{bar='item2'}]
  </code></pre>
  
  <p>And my pom :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.question&lt;/groupId&gt;
      &lt;artifactId&gt;beanutils&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;4.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Why is the spring beanutils not clone a list field ?</p>