Bug 77509 OperationCanceledException when clicking Cancel while doing organize imports on project
I200411010800 + plug-in export Select Java project with JUnit and start to organize the imports. Click "Cancel" ==> org.eclipse.core.runtime.OperationCanceledException at org.eclipse.core.internal.jobs.ThreadJob.joinRun(ThreadJob.java:137) at org.eclipse.core.internal.jobs.ImplicitJobs.begin(ImplicitJobs.java:87) at org.eclipse.core.internal.jobs.JobManager.beginRule(JobManager.java:183) at org.eclipse.core.internal.resources.WorkManager.checkIn(WorkManager.java:95) at org.eclipse.core.internal.resources.Workspace.prepareOperation(Workspace.java:1631) at org.eclipse.core.internal.resources.File.setContents(File.java:335) at org.eclipse.core.internal.resources.File.setContents(File.java:439) at org.eclipse.core.internal.filebuffers.ResourceTextFileBuffer.commitFileBufferContent(ResourceTextFileBuffer.java:275) at org.eclipse.core.internal.filebuffers.ResourceFileBuffer.commit(ResourceFileBuffer.java:317) at org.eclipse.jdt.internal.corext.codemanipulation.ImportsStructure.commitDocument(ImportsStructure.java:812) at org.eclipse.jdt.internal.corext.codemanipulation.ImportsStructure.create(ImportsStructure.java:763) at org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.run(OrganizeImportsOperation.java:348) at org.eclipse.jdt.ui.actions.OrganizeImportsAction$3.run(OrganizeImportsAction.java:384) at org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:145) at org.eclipse.ui.internal.UISynchronizer$1.run(UISynchronizer.java:36) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:118) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:2771) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2451) at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:141) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:279) at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:447) at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:263) at org.eclipse.ui.internal.progress.ProgressManager$3.run(ProgressManager.java:840) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69) at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:874) at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:850) at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1042) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.runOnMultiple(OrganizeImportsAction.java:295) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.run(OrganizeImportsAction.java:281) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:212) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:188) at org.eclipse.jface.action.Action.runWithEvent(Action.java:988) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:946) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:896) at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:810) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:800) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2794) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2448) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1527) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1498) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:276) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:102) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:704) at org.eclipse.core.launcher.Main.main(Main.java:688)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OrganizeImportsAction.java
status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
						} 	
					} catch (CoreException e) {
						JavaPlugin.log(e);
						String message= ActionMessages.getFormattedString("OrganizeImportsAction.multi.error.unexpected", e.getStatus().getMessage()); 
						status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));					
					}
					if (monitor.isCanceled()) {
						throw new OperationCanceledException();
					}
				}
			}
		} finally {
			monitor.done();
		}
	}
	
	private boolean testOnBuildPath(ICompilationUnit cu, MultiStatus status) {
		IJavaProject project= cu.getJavaProject();
		if (!project.isOnClasspath(cu)) {
			String cuLocation= cu.getPath().makeRelative().toString();
			String message= ActionMessages.getFormattedString("OrganizeImportsAction.multi.error.notoncp", cuLocation); 
			status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
			return false;
		}
		return true;
	}
	
		
	private void runInSync(final OrganizeImportsOperation op, final String cuLocation, final MultiStatus status, final IProgressMonitor monitor) {