Skip to content

Commit 7fe83e4

Browse files
EcljpseB0Tjukzi
authored andcommitted
IStatusLineManager.getProgressMonitor(): fix multiple invocations
ignore call to done() if beginTask() was not called! eclipse-jdt/eclipse.jdt.ui#61
1 parent 324229d commit 7fe83e4

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/action/IStatusLineManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
*/
3232
public interface IStatusLineManager extends IContributionManager {
3333
/**
34-
* Returns a progress monitor which reports progress in the status line.
34+
* Creates a new progress monitor which reports progress in the status line.
3535
* Note that the returned progress monitor may only be accessed from the UI
3636
* thread.
3737
*
3838
* @return the progress monitor
3939
*
4040
* Note: There is a delay after a beginTask message before the
4141
* monitor is shown. This may not be appropriate for all apps.
42+
* @see IProgressMonitor
4243
*/
4344
public IProgressMonitor getProgressMonitor();
4445

bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineManager.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,29 @@ public IProgressMonitor getProgressMonitor() {
149149
: new NullProgressMonitor();
150150

151151
return new IProgressMonitor() {
152+
private volatile boolean taskStarted;
152153

153154
@Override
154155
public void beginTask(String name, int totalWork) {
156+
if (taskStarted) {
157+
throw new IllegalStateException("beginTask must only be called once per instance"); //$NON-NLS-1$
158+
}
159+
taskStarted = true;
160+
// According to the IProgressMonitor javadoc beginTask() must only be called
161+
// once on a given progress monitor instance.
162+
// However it works in this case multiple times if done() was called in between.
155163
progressDelegate.beginTask(name, totalWork);
156-
157164
}
158165

159166
@Override
160167
public void done() {
168+
if (!taskStarted) {
169+
// ignore call to done() if beginTask() was not called!
170+
// Otherwise an otherwise already started delegate would be finished
171+
// see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61
172+
return;
173+
}
174+
taskStarted = false;
161175
progressDelegate.done();
162176
}
163177

@@ -182,6 +196,9 @@ public void setCanceled(boolean value) {
182196

183197
@Override
184198
public void setTaskName(String name) {
199+
if (!taskStarted) {
200+
throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$
201+
}
185202
progressDelegate.setTaskName(name);
186203

187204
}
@@ -194,6 +211,9 @@ public void subTask(String name) {
194211

195212
@Override
196213
public void worked(int work) {
214+
if (!taskStarted) {
215+
throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$
216+
}
197217
progressDelegate.worked(work);
198218
}
199219

0 commit comments

Comments
 (0)