Bug 299731 [Progress] ProgressMonitorDialog should check for widget state in its async runnable
setOperationCancelButtonEnabled(boolean) should check whether the widget has been disposed or not before invoking setEnabled(boolean). Since this method is called in an asynchronous runnable, there is no guarantee that the widgets are still up when the display gets around to processing them. Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); shell.pack(); shell.open(); ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell); pmd.open(); pmd.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed) at org.eclipse.swt.SWT.error(SWT.java:4068) at org.eclipse.swt.SWT.error(SWT.java:3983) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3906) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3527) at org.eclipse.ui.Test.main(Test.java:45) Caused by: org.eclipse.swt.SWTException: Widget is disposed at org.eclipse.swt.SWT.error(SWT.java:4068) at org.eclipse.swt.SWT.error(SWT.java:3983) at org.eclipse.swt.SWT.error(SWT.java:3954) at org.eclipse.swt.widgets.Widget.error(Widget.java:467) at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340) at org.eclipse.swt.widgets.Control.setEnabled(Control.java:2928) at org.eclipse.jface.dialogs.ProgressMonitorDialog.setOperationCancelButtonEnabled(ProgressMonitorDialog.java:622) at org.eclipse.jface.dialogs.ProgressMonitorDialog$1.run(ProgressMonitorDialog.java:329) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134) ... 3 more
bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/ProgressMonitorDialog.java
* runnables - this dialog should be discarded after completion of one
 * IRunnableWithProgress and a new one instantiated for use by a second or
 * sebsequent IRunnableWithProgress to ensure proper initialization.
 * </p>
 * <p>
 * Note that not forking the process will result in it running in the UI which
 * may starve the UI. The most obvious symptom of this problem is non
 * responsiveness of the cancel button. If you are running within the UI Thread
 * you should do the bulk of your work in another Thread to prevent starvation.
 * It is recommended that fork is set to true in most cases.
 * </p>
 */
public class ProgressMonitorDialog extends IconAndMessageDialog implements
		IRunnableContext {
	/**
	 * Name to use for task when normal task name is empty string.
	 */
	private static String DEFAULT_TASKNAME = JFaceResources
			.getString("ProgressMonitorDialog.message"); 
	/**
	 * Constants for label and monitor size
	 */
	private static int LABEL_DLUS = 21;
	private static int BAR_DLUS = 9;
	/**
	 * The progress indicator control.
	 */
	protected ProgressIndicator progressIndicator;
	/**
	 * The label control for the task. Kept for backwards compatibility.