Bug 44166 npe in organize imports [code manipulation]
3.0M3 on linux gtk i found this in the log java.lang.NullPointerException at org.eclipse.jdt.ui.actions.OrganizeImportsAction.doListSelectionChanged(OrganizeImportsAction.java:492) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.access$2(OrganizeImportsAction.java:489) at org.eclipse.jdt.ui.actions.OrganizeImportsAction$5.handleSelectionChanged(OrganizeImportsAction.java:466) at org.eclipse.ui.dialogs.AbstractElementListSelectionDialog.handleWidgetSelected(AbstractElementListSelectionDialog.java:384) at org.eclipse.ui.dialogs.AbstractElementListSelectionDialog.access$0(AbstractElementListSelectionDialog.java:374) at org.eclipse.ui.dialogs.AbstractElementListSelectionDialog$1.widgetSelected(AbstractElementListSelectionDialog.java:364) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:953) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1872) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1652) at org.eclipse.jface.window.Window.runEventLoop(Window.java:583) at org.eclipse.jface.window.Window.open(Window.java:563) at org.eclipse.ui.dialogs.AbstractElementListSelectionDialog.open(AbstractElementListSelectionDialog.java:430) at org.eclipse.jdt.internal.ui.dialogs.MultiElementListSelectionDialog.open(MultiElementListSelectionDialog.java:107) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.doChooseImports(OrganizeImportsAction.java:472) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.access$1(OrganizeImportsAction.java:456) at org.eclipse.jdt.ui.actions.OrganizeImportsAction$4.chooseImports(OrganizeImportsAction.java:451) at org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.run(OrganizeImportsOperation.java:514) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:34) at org.eclipse.jdt.internal.core.JavaModelOperation.execute(JavaModelOperation.java:365) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:704) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1571) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1588) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:2914) at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:42) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.internalRun(BusyIndicatorRunnableContext.java:113) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.run(BusyIndicatorRunnableContext.java:80) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:84) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext.run(BusyIndicatorRunnableContext.java:126) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.run(OrganizeImportsAction.java:418) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.run(OrganizeImportsAction.java:270) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:194) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:172) at org.eclipse.jface.action.Action.runWithEvent(Action.java:842) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:529) at org.eclipse.jface.action.ActionContributionItem.access$4(ActionContributionItem.java:482) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:454) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:953)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OrganizeImportsAction.java
private boolean hasSourceFolders(IJavaProject project) throws JavaModelException {
		IPackageFragmentRoot[] roots= project.getPackageFragmentRoots();
		for (int i= 0; i < roots.length; i++) {
			IPackageFragmentRoot root= roots[i];
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				return true;
			}
		}
		return false;
	}
	/* (non-Javadoc)
	 * Method declared on SelectionDispatchAction.
	 */
	public void run(ITextSelection selection) {
		run(getCompilationUnit(fEditor));
	}
	private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
		IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
		ICompilationUnit cu= manager.getWorkingCopy(editor.getEditorInput());
		return cu;
	}
	
	/* (non-Javadoc)
	 * Method declared on SelectionDispatchAction.
	 */
	public void run(IStructuredSelection selection) {
		ICompilationUnit[] cus= getCompilationUnits(selection);
		if (cus.length == 1) {
			run(cus[0]);
		} else {