Reviewers: ecc,

Description:
java.lang.IndexOutOfBoundsException: No child at index -1
when findDeepestOpenChild(FastTree.java:792) is called.

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

Affected files:
   src/com/google/gwt/gen2/complexpanel/client/FastTree.java
   test/com/google/gwt/gen2/complexpanel/client/FastTreeTest.java


Index: test/com/google/gwt/gen2/complexpanel/client/FastTreeTest.java
===================================================================
--- test/com/google/gwt/gen2/complexpanel/client/FastTreeTest.java       
(revision 1542)
+++ test/com/google/gwt/gen2/complexpanel/client/FastTreeTest.java      
(working  
copy)
@@ -271,6 +271,24 @@
      assertTrue(item3.isSelected());
      assertFalse(item1.isSelected());
    }
+
+  public void testFindDeepestOpenChild() {
+    FastTree tree = createBeforeSelectTestableTree(false);
+    FastTreeItem item = tree.getItem(0);
+    item.setState(true);
+    tree.setSelectedItem(item);
+    assertTrue(item.isOpen());
+    assertEquals(2, item.getChildCount());
+
+    // no try something funky
+    item.removeItems();
+
+    try {
+      assertNotNull(tree.findDeepestOpenChild(item));
+    } catch (IndexOutOfBoundsException iobe) {
+      fail("Out of bound exception thrown!");
+    }
+  }

    /**
     * helper method for testing beforeSelect event.
Index: src/com/google/gwt/gen2/complexpanel/client/FastTree.java
===================================================================
--- src/com/google/gwt/gen2/complexpanel/client/FastTree.java   (revision  
1542)
+++ src/com/google/gwt/gen2/complexpanel/client/FastTree.java   (working copy)
@@ -694,6 +694,14 @@
      // Logical detach.
      childWidgets.remove(widget);
    }
+
+  // @VisibleForTesting
+  FastTreeItem findDeepestOpenChild(FastTreeItem item) {
+    if (!item.isOpen() || item.getChildCount() == 0) {
+      return item;
+    }
+    return findDeepestOpenChild(item.getChild(item.getChildCount() - 1));
+  }

    /**
     * Helper to build the root item.
@@ -788,13 +796,6 @@
      return;
    }

-  private FastTreeItem findDeepestOpenChild(FastTreeItem item) {
-    if (!item.isOpen()) {
-      return item;
-    }
-    return findDeepestOpenChild(item.getChild(item.getChildCount() - 1));
-  }
-
    private FastTreeItem findItemByChain(ArrayList<Element> chain, int index,
        FastTreeItem root) {
      if (index == chain.size()) {



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

Reply via email to