[ https://issues.apache.org/jira/browse/GROOVY-7044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15159688#comment-15159688 ]
ASF GitHub Bot commented on GROOVY-7044: ---------------------------------------- GitHub user daspilker opened a pull request: https://github.com/apache/groovy/pull/270 GROOVY-7044: Fixed deep cloning of nodes generated by NodeBuilder Use default behavior when creating Nodes without value. You can merge this pull request into a Git repository by running: $ git pull https://github.com/daspilker/groovy GROOVY-7044 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/270.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #270 ---- commit 7b99e656e734b14872048354731b01d9d3061af6 Author: Daniel Spilker <daniel.spil...@coremedia.com> Date: 2016-02-23T21:34:09Z GROOVY-7044: Fixed deep cloning of nodes generated by NodeBuilder Use default behavior when creating Nodes without value. ---- > Cloned NodeBuilder created nodes share values (child nodes) with original > node. > ------------------------------------------------------------------------------- > > Key: GROOVY-7044 > URL: https://issues.apache.org/jira/browse/GROOVY-7044 > Project: Groovy > Issue Type: Bug > Components: groovy-jdk, XML Processing > Affects Versions: 2.3.6 > Reporter: Damir Perovi? > Priority: Minor > Attachments: NodeBuilderTest.groovy > > > Cloning nodes created by NodeBuilder share child nodes with original node. > If node is added to original node or child node value is changed, the cloned > node will see those changes. Same applies to cloned node, adding node or > changing child node value will be seen by original node. > The problem seem to originate in NodeBuilder methods: > {code} > protected Object createNode(Object name) > protected Object createNode(Object name, Map attributes) > {code} > which use ArrayList when creating new Node instead of NodeList. > Can be easily reproduced by groovysh or use attached junit file. > {noformat} > groovy:000> x1 = new NodeBuilder().a() { b() } > ===> a[attributes={}; value=[b[attributes={}; value=[]]]] > groovy:000> x2 = x1.clone() > ===> a[attributes={}; value=[b[attributes={}; value=[]]]] > groovy:000> x1.appendNode('c') > ===> c[attributes={}; value=[]] > groovy:000> x1 > ===> a[attributes={}; value=[b[attributes={}; value=[]], c[attributes={}; > value=[]]]] > groovy:000> x2 > ===> a[attributes={}; value=[b[attributes={}; value=[]], c[attributes={}; > value=[]]]] > groovy:000> x1.b[0].setValue(1) > ===> null > groovy:000> x1 > ===> a[attributes={}; value=[b[attributes={}; value=1], c[attributes={}; > value=[]]]] > groovy:000> x2 > ===> a[attributes={}; value=[b[attributes={}; value=1], c[attributes={}; > value=[]]]] > groovy:000> x2.c[0].setValue(2) > ===> null > groovy:000> x1 > ===> a[attributes={}; value=[b[attributes={}; value=1], c[attributes={}; > value=2]]] > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)