summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2013-02-25 12:00:31 +0200
committerVaadin Code Review <review@vaadin.com>2013-02-25 10:09:43 +0000
commit9a59383cd7a0a87c76eeed38a18273f661d95b1b (patch)
tree8979f84fb3567b66ccb6157b0ed4c6425b39f5b5 /server
parentdf430d5d16f18cfd771f01863193f547e0d0f2e7 (diff)
downloadvaadin-framework-9a59383cd7a0a87c76eeed38a18273f661d95b1b.tar.gz
vaadin-framework-9a59383cd7a0a87c76eeed38a18273f661d95b1b.zip
Fixed NPE in Tree when calling non-final constructor #11132
Change-Id: Ie2b44368513c9b51c184f473d429ec9d3e56b8c7
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Tree.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java
index 32c5712f0f..2c16a36a6c 100644
--- a/server/src/com/vaadin/ui/Tree.java
+++ b/server/src/com/vaadin/ui/Tree.java
@@ -75,7 +75,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
/**
* Set of expanded nodes.
*/
- private final HashSet<Object> expanded = new HashSet<Object>();
+ private HashSet<Object> expanded = new HashSet<Object>();
/**
* List of action handlers.
@@ -845,9 +845,20 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
newDataSource));
}
- // Ensure previous expanded items are cleaned up if they don't exist in
- // the new container
- cleanupExpandedItems();
+ /*
+ * Ensure previous expanded items are cleaned up if they don't exist in
+ * the new container
+ */
+ if (expanded != null) {
+ /*
+ * We need to check that the expanded-field is not null since
+ * setContainerDataSource() is called from the parent constructor
+ * (AbstractSelect()) and at that time the expanded field is not yet
+ * initialized.
+ */
+ cleanupExpandedItems();
+ }
+
}
/* Expand event and listener */
@@ -1652,7 +1663,6 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
target.addAttribute("depth", depthToCheck);
target.addAttribute("key", key(rootId));
}
-
}
/**
@@ -1688,13 +1698,15 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
}
private void cleanupExpandedItems() {
+ Set<Object> removedItemIds = new HashSet<Object>();
for (Object expandedItemId : expanded) {
if (getItem(expandedItemId) == null) {
- expanded.remove(expandedItemId);
+ removedItemIds.add(expandedItemId);
if (this.expandedItemId == expandedItemId) {
this.expandedItemId = null;
}
}
}
+ expanded.removeAll(removedItemIds);
}
}