Bug 163357 [Viewers] NullPointerException on AbstractTreeViewer.remove(path, index)
I20061102-1715 It's possible to get an NPE when removing an element from a tree viewer. The remove API accepts a "parent path" and "child index". It is possible to specify an empty tree path for the parent to indicate the root element. However, the remove code eventually trys to find the widget associated with the "last segment" of the parent path. This results in null, and an NPE: Caused by: java.lang.NullPointerException at org.eclipse.jface.viewers.CustomHashtable.hashCode(CustomHashtable.java:265) at org.eclipse.jface.viewers.CustomHashtable.get(CustomHashtable.java:237) at org.eclipse.jface.viewers.StructuredViewer.findItems(StructuredViewer.java:769) at org.eclipse.jface.viewers.AbstractTreeViewer.internalFindItem(AbstractTreeViewer.java:173) at org.eclipse.jface.viewers.AbstractTreeViewer.internalFindItems(AbstractTreeViewer.java:153) at org.eclipse.jface.viewers.TreeViewer$8.run(TreeViewer.java:1017) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1326) at org.eclipse.jface.viewers.TreeViewer.remove(TreeViewer.java:1005) at org.eclipse.debug.internal.ui.viewers.model.ChildrenUpdate.performUpdate(ChildrenUpdate.java:62) at org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor$1.runInUIThread(ViewerUpdateMonitor.java:43) at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:94) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123) ... 20 more
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
/**
 * A concrete viewer based on an SWT <code>Tree</code> control.
 * <p>
 * This class is not intended to be subclassed outside the viewer framework. It
 * is designed to be instantiated with a pre-existing SWT tree control and
 * configured with a domain-specific content provider, label provider, element
 * filter (optional), and element sorter (optional).
 * </p>
 * <p>
 * Content providers for tree viewers must implement either the
 * {@link ITreeContentProvider} interface, (as of 3.2) the
 * {@link ILazyTreeContentProvider} interface, or (as of 3.3) the
 * {@link ILazyTreePathContentProvider}. If the content provider is an
 * <code>ILazyTreeContentProvider</code> or an
 * <code>ILazyTreePathContentProvider</code>, the underlying Tree must be
 * created using the {@link SWT#VIRTUAL} style bit, and the tree viewer will not
 * support sorting or filtering.
 * </p>
 */
public class TreeViewer extends AbstractTreeViewer {