]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java
Filter conflicting changes (deleted + added at the same time)
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / base / ParentNode.java
index 7da387d7fa5866ae6a5e6117000ee6b48837c044..5c834fba1dd8b89233f1dbc4e33c5f9a30fb42a4 100644 (file)
@@ -12,7 +12,6 @@
 package org.simantics.g3d.scenegraph.base;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 
 import org.simantics.utils.datastructures.MapList;
@@ -22,8 +21,13 @@ public abstract class ParentNode<T extends INode> extends Node {
        private MapList<String, T> children = new MapList<String, T>();
 
        public synchronized void addNode(String relName, T child) {
-               if (child.getParent() != null)
+           if (child == null)
+               throw new NullPointerException("Cannot add null child");
+               if (child.getParent() != null) {
+                   if (child.getParent() == this)
+                       throw new IllegalArgumentException("Given node is already a child");
                        child.getParent().deattachNode(child.getParentRel(), child);
+               }
 
                child.setParent(this, relName);
                children.add(relName, (T) child);