Bug 249514 [Viewers] [JFace] NPE setting StructuredSelection(Object[])
Build ID: I20080617-2000 Steps To Reproduce: 1. Pass null to new StructuredSelection(Object[]) 2. Watch NPE occur More information: The problem is there is no check on the the constructor for a null array. The javadoc doesn't specify that null is an illegal value, but looking at the class, it appears the other constructors do not allow null. Proposed fix: * Update the javadoc to say null is not allowed * Add an Assert.isNotNull to the constructor to match other constructors. Stacktrace: Thread [main] (Suspended (exception NullPointerException)) StructuredSelection.<init>(Object[]) line: 61 CategoriesView(SmalltalkBrowsingPart).selectAll(boolean) line: 864 CategoriesView.setSelection(IStructuredSelection, boolean) line: 274 CategoriesView(SmalltalkBrowsingPart).adjustInputAndSetSelection(Object) line: 797 CategoriesView.adjustInputAndSetSelection(Object) line: 253 CategoriesView(SmalltalkBrowsingPart).selectionChanged(IWorkbenchPart, ISelection) line: 731 CategoriesView.selectionChanged(IWorkbenchPart, ISelection) line: 224 PageSelectionService(AbstractSelectionService).firePostSelection(IWorkbenchPart, ISelection) line: 179 AbstractSelectionService$2.selectionChanged(SelectionChangedEvent) line: 71 StructuredViewer$3.run() line: 842 SafeRunner.run(ISafeRunnable) line: 37 Platform.run(ISafeRunnable) line: 880 JFaceUtil$1.run(ISafeRunnable) line: 48 SafeRunnable.run(ISafeRunnable) line: 175 TreeViewer(StructuredViewer).firePostSelectionChanged(SelectionChangedEvent) line: 840 TreeViewer(StructuredViewer).handlePostSelect(SelectionEvent) line: 1153 StructuredViewer$5.widgetSelected(SelectionEvent) line: 1178 OpenStrategy.firePostSelectionEvent(SelectionEvent) line: 251 OpenStrategy.access$5(OpenStrategy, SelectionEvent) line: 245 OpenStrategy$3.run() line: 419 RunnableLock.run() line: 35 UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 133 Display.runAsyncMessages(boolean) line: 3800 Display.readAndDispatch() line: 3425 Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2382 Workbench.runUI() line: 2346 Workbench.access$4(Workbench) line: 2198 Workbench$5.run() line: 493 Realm.runWithDefault(Realm, Runnable) line: 288 Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 488 PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149 IDEApplication.start(IApplicationContext) line: 113 EclipseAppHandle.run(Object) line: 193 EclipseAppLauncher.runApplication(Object) line: 110 EclipseAppLauncher.start(Object) line: 79 EclipseStarter.run(Object) line: 382 EclipseStarter.run(String[], Runnable) line: 179 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 45 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 612 Main.invokeFramework(String[], URL[]) line: 549 Main.basicRun(String[]) line: 504 Main.run(String[]) line: 1236 Main.main(String[]) line: 1212
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java
private IElementComparer comparer;
    /**
     * The canonical empty selection. This selection should be used instead of
     * <code>null</code>.
     */
    public static final StructuredSelection EMPTY = new StructuredSelection();
    /**
     * Creates a new empty selection.  
     * See also the static field <code>EMPTY</code> which contains an empty selection singleton.
     *
     * @see #EMPTY
     */
    public StructuredSelection() {
    }
    /**
     * Creates a structured selection from the given elements.
     *
     * @param elements an array of elements
     */
    public StructuredSelection(Object[] elements) {
        this.elements = new Object[elements.length];
        System.arraycopy(elements, 0, this.elements, 0, elements.length);
    }
    /**
     * Creates a structured selection containing a single object.
     * The object must not be <code>null</code>.
     *
     * @param element the element
     */
    public StructuredSelection(Object element) {