Bug 59211 NPE from RemoveFromClasspathAction when double clicking on a new jar in a ClasspathContainer
I have written an IClasspathContainer with an Initializer to sync the classpath with an external file. When the file I am monitoring changes the contents of the container is updated with the new jars, but when I double click on the jar to see the contents I get the following exception: java.lang.NullPointerException at org.eclipse.jdt.ui.actions.RemoveFromClasspathAction.canRemove(RemoveFromClasspathAction.java:134) at org.eclipse.jdt.ui.actions.RemoveFromClasspathAction.checkEnabled(RemoveFromClasspathAction.java:78) at org.eclipse.jdt.ui.actions.RemoveFromClasspathAction.selectionChanged(RemoveFromClasspathAction.java:71) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java:200) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged(SelectionDispatchAction.java:195) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:159) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java(Inlined Compiled Code)) at org.eclipse.core.runtime.Platform.run(Platform.java(Compiled Code)) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1310) at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:666) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:690) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:309) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java(Inlined Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java(Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1536) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:257) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:139) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:90) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:277) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:239) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41) at java.lang.reflect.Method.invoke(Method.java:371) at org.eclipse.core.launcher.Main.basicRun(Main.java:267) at org.eclipse.core.launcher.Main.run(Main.java:692) at org.eclipse.core.launcher.Main.main(Main.java:676) As another point if I click the + button by the jar the + symbol disappears and I don't see any error. After restarting eclipse the jar's contents is correctly displayed.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/RemoveFromClasspathAction.java
for (Iterator iter= selection.iterator(); iter.hasNext();) {
			if (! canRemove(iter.next()))
				return false;
		}
		return true;
	}
	
	/* (non-Javadoc)
	 * Method declared in SelectionDispatchAction
	 */
	public void run(final IStructuredSelection selection) {
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, new WorkbenchRunnableAdapter(new IWorkspaceRunnable() {
				public void run(IProgressMonitor pm) throws CoreException {
					try{
						IPackageFragmentRoot[] roots= getRootsToRemove(selection);
						pm.beginTask(ActionMessages.getString("RemoveFromClasspathAction.Removing"), roots.length); 
						for (int i= 0; i < roots.length; i++) {
							int jCoreFlags= IPackageFragmentRoot.NO_RESOURCE_MODIFICATION | IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH;
							roots[i].delete(IResource.NONE, jCoreFlags, new SubProgressMonitor(pm, 1));
						}
					} finally {
						pm.done();
					}
				}
		}));
		} catch (InvocationTargetException e) {
			ExceptionHandler.handle(e, getShell(), 
					ActionMessages.getString("RemoveFromClasspathAction.exception_dialog_title"), 
					ActionMessages.getString("RemoveFromClasspathAction.Problems_occurred"));