View Full Version : TreePanel Throws Exceptions Using Drag and Drop

2 Nov 2011, 4:08 AM
The code in TreePanel throws sporadic exceptions when dragging and dropping tree nodes from one parent to another, due to the findChildren() method assuming the call to findNode() always returns a valid value and thus attempts to dereference it even when it's null, causing a NullPointerException to be thrown. In addition to findChildren(), there are number of other places in this class where the return value from findNode() is not checked and thus potentially have the same problem when null is returned. This breaks drag and drop in my usage of it because it attempts to call onAdd(), update(), and clean() when a tree node is dropped onto a new parent, and in turn findNode() is called for the moved tree node and it returns null.

Please check the return value from findNode() before using it in this class:

private void findChildren(M parent, List<M> list, boolean onlyVisible) {
for (M child : store.getChildren(parent)) {
if (!onlyVisible || findNode(child).isExpanded()) {
findChildren(child, list, onlyVisible);

Colin Alworth
4 Nov 2011, 10:40 AM
Need a little more info to proceed with this - all invocations of the private method TreeStore.findChildren are guaranteed to have non-null param children, and parent can only be null in the case where the item you are removing from the tree was never in the tree, or where a sub-item of the tree has a child 'null', which doesn't make a lot of sense.

Both of the TreePanel.findNode calls in TreePanelDragSource/TreePanelDropTarget are null checked, and TreePanel.findNode doesnt seem to invoke TreePanel.findChildren nor TreeStore.findChildren.

Testing with the TreePanel dnd sample at http://www.sencha.com/examples/explorer.html#treetotree and http://www.sencha.com/examples/explorer.html#reorderingtree I can't quickly find any cases where dragging from a parent (root or otherwise) causes an exception.

Can you provide a set of steps to reproduce this (or a working example, if not possible in the samples)? Perhaps also qualify the method names in your post, so it is clear which invocations of findChildren and findNode you are referring to?