diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/IStatusLineManager.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/IStatusLineManager.java index f2a312c1c51..f72469b869e 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/IStatusLineManager.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/IStatusLineManager.java @@ -31,7 +31,7 @@ */ public interface IStatusLineManager extends IContributionManager { /** - * Returns a progress monitor which reports progress in the status line. + * Creates a new progress monitor which reports progress in the status line. * Note that the returned progress monitor may only be accessed from the UI * thread. * @@ -39,6 +39,7 @@ public interface IStatusLineManager extends IContributionManager { * * Note: There is a delay after a beginTask message before the * monitor is shown. This may not be appropriate for all apps. + * @see IProgressMonitor */ public IProgressMonitor getProgressMonitor(); diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineManager.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineManager.java index 7e4d9f146cf..6051bde890a 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineManager.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineManager.java @@ -149,15 +149,29 @@ public IProgressMonitor getProgressMonitor() { : new NullProgressMonitor(); return new IProgressMonitor() { + private volatile boolean taskStarted; @Override public void beginTask(String name, int totalWork) { + if (taskStarted) { + throw new IllegalStateException("beginTask must only be called once per instance"); //$NON-NLS-1$ + } + taskStarted = true; + // According to the IProgressMonitor javadoc beginTask() must only be called + // once on a given progress monitor instance. + // However it works in this case multiple times if done() was called in between. progressDelegate.beginTask(name, totalWork); - } @Override public void done() { + if (!taskStarted) { + // 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 = false; progressDelegate.done(); } @@ -182,6 +196,9 @@ public void setCanceled(boolean value) { @Override public void setTaskName(String name) { + if (!taskStarted) { + throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$ + } progressDelegate.setTaskName(name); } @@ -194,6 +211,9 @@ public void subTask(String name) { @Override public void worked(int work) { + if (!taskStarted) { + throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$ + } progressDelegate.worked(work); }