Skip to content

Commit

Permalink
Apparently the super.clone() does not clone the pointer to the IAtomC…
Browse files Browse the repository at this point in the history
…ontainer[], causing a clone() followed by changing containers in the clone to overwrite the original IAtomContainer[]. Fixed by creating a new array.

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Apr 7, 2010
1 parent 068fb3b commit 4e5d6a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/org/openscience/cdk/AtomContainerSet.java
Expand Up @@ -365,9 +365,11 @@ public String toString() {
*/
public Object clone() throws CloneNotSupportedException {
AtomContainerSet clone = (AtomContainerSet)super.clone();
clone.atomContainers = new AtomContainer[atomContainerCount];
clone.atomContainerCount = 0;
for (int i = 0; i < atomContainerCount; i++) {
clone.replaceAtomContainer(i, (IAtomContainer)atomContainers[i].clone());
clone.setMultiplier(i, getMultiplier(i));
clone.addAtomContainer((IAtomContainer)atomContainers[i].clone());
clone.setMultiplier(i, getMultiplier(i));
}
return clone;
}
Expand Down

0 comments on commit 4e5d6a1

Please sign in to comment.