diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java index 40d716c11f7..313d990ca75 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java @@ -19,7 +19,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ProgressMonitorWrapper; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.util.Policy; import org.eclipse.swt.widgets.Display; /** @@ -56,6 +58,8 @@ private String currentTask = ""; //$NON-NLS-1$ + private volatile Exception taskStarted; + private class Collector implements Runnable { private String taskName; @@ -140,6 +144,15 @@ public AccumulatingProgressMonitor(IProgressMonitor monitor, Display display) { @Override public void beginTask(final String name, final int totalWork) { + if (taskStarted != null) { + Exception e = new IllegalStateException( + "beginTask should only be called once per instance. At least call done() before further invocations", //$NON-NLS-1$ + taskStarted); + Policy.getLog().log(Status.warning(e.getLocalizedMessage(), e)); + done(); // workaround client error + } + taskStarted = new IllegalStateException( + "beginTask(" + name + ", " + totalWork + ") was called here previously"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ synchronized (this) { collector = null; } @@ -177,6 +190,13 @@ private void createCollector(String taskName, String subTask, double work) { @Override public void done() { + if (taskStarted == null) { + // ignore call to done() if beginTask() was not called! + // Otherwise an otherwise already started delegate would be finished + // see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61 + return; + } + taskStarted = null; synchronized (this) { collector = null; }