Reviewers: skybrian,

Description:
Ensures that we cleanup CellTree nodes when we are done using them.
Currently, some deleted nodes aren't cleaned up, which leads to JS
errors when the last node of a CellTree is removed. Even when the errors
do not occur, forgetting to cleanup the nodes leaves stale event
handlers on the tree.

Issue: 6677


Please review this at http://gwt-code-reviews.appspot.com/1542803/

Affected files:
  M user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java
M user/test/com/google/gwt/user/cellview/client/AbstractCellTreeTestBase.java


Index: user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java (revision 10615) +++ user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java (working copy)
@@ -211,7 +211,8 @@
         int childCount = nodeView.children.size();
         while (childCount > size) {
           childCount--;
-          nodeView.children.remove(childCount);
+ CellTreeNodeView<?> deleted = nodeView.children.remove(childCount);
+          deleted.cleanup(true);
         }

         // Reattach the open nodes.
Index: user/test/com/google/gwt/user/cellview/client/AbstractCellTreeTestBase.java
===================================================================
--- user/test/com/google/gwt/user/cellview/client/AbstractCellTreeTestBase.java (revision 10615) +++ user/test/com/google/gwt/user/cellview/client/AbstractCellTreeTestBase.java (working copy)
@@ -202,6 +202,24 @@
     return "com.google.gwt.user.cellview.CellView";
   }

+  /**
+   * Issue 6677: Deleting the last element on a CellTree causes NPE in IE.
+   */
+  public void testDeleteLastNode() {
+    // Remove all but the last tree node from the model.
+    TreeNode root = tree.getRootTreeNode();
+    for (int i = 0; i < 9; i++) {
+      model.rootDataProvider.getList().remove(0);
+    }
+    model.rootDataProvider.flush();
+    assertEquals(1, root.getChildCount());
+
+    // Remove the last tree node.
+    model.rootDataProvider.getList().remove(0);
+    model.rootDataProvider.flush();
+    assertEquals(0, root.getChildCount());
+  }
+
   public void testGetRootNode() {
     TreeNode root = tree.getRootTreeNode();
     assertEquals(10, root.getChildCount());


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to