Skip to content

Commit

Permalink
IStatusLineManager.getProgressMonitor(): fix multiple invocations
Browse files Browse the repository at this point in the history
ignore call to done() if beginTask() was not called!

eclipse-jdt/eclipse.jdt.ui#61
  • Loading branch information
EcljpseB0T committed Sep 1, 2023
1 parent 81e7679 commit d61ef80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
*/
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.
*
* @return the progress monitor
*
* 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);

}
Expand All @@ -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);
}

Expand Down

0 comments on commit d61ef80

Please sign in to comment.