Author: heuermh
Date: Tue Oct  7 13:57:52 2008
New Revision: 397

Modified:
    piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java

Log:
Issue 23 ; check for existence of a node before removal to prevent  
NullPointerExceptions

Modified:  
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java
==============================================================================
--- piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java       
 
(original)
+++ piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java       
 
Tue Oct  7 13:57:52 2008
@@ -2888,7 +2888,11 @@
       * @return the removed child
       */
      public PNode removeChild(PNode child) {
-        return removeChild(indexOfChild(child));
+        int index = indexOfChild(child);
+        if (index == -1) {
+            return null;
+        }
+        return removeChild(index);
      }

      /**
@@ -2900,6 +2904,9 @@
       * @return the removed child
       */
      public PNode removeChild(int index) {
+        if (children == null) {
+            return null;
+        }
          PNode child = (PNode) children.remove(index);

          if (children.size() == 0) {

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to