Skip to content

Commit 9ee7888

Browse files
EcljpseB0Tiloveeclipse
authored andcommitted
StatusLineManager: improve error with callstack
eclipse-jdt/eclipse.jdt.ui#61
1 parent 9b60203 commit 9ee7888

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
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
@@ -33,7 +33,8 @@ public interface IStatusLineManager extends IContributionManager {
3333
/**
3434
* 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
36-
* thread.
36+
* thread. Reusing the monitor requires to finally call progressMonitor.done()
37+
* before using it again.
3738
*
3839
* @return the progress monitor
3940
*

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ public IProgressMonitor getProgressMonitor() {
149149
: new NullProgressMonitor();
150150

151151
return new IProgressMonitor() {
152-
private volatile boolean taskStarted;
152+
private volatile Exception taskStarted;
153153

154154
@Override
155155
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$
156+
if (taskStarted != null) {
157+
throw new IllegalStateException(
158+
"beginTask should only be called once per instance. At least call done() before further invocations", //$NON-NLS-1$
159+
taskStarted);
158160
}
159-
taskStarted = true;
161+
taskStarted = new IllegalStateException(
162+
"beginTask(" + name + ", " + totalWork + ") was called here previously"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
160163
// According to the IProgressMonitor javadoc beginTask() must only be called
161164
// once on a given progress monitor instance.
162165
// However it works in this case multiple times if done() was called in between.
@@ -165,13 +168,13 @@ public void beginTask(String name, int totalWork) {
165168

166169
@Override
167170
public void done() {
168-
if (!taskStarted) {
171+
if (taskStarted == null) {
169172
// ignore call to done() if beginTask() was not called!
170173
// Otherwise an otherwise already started delegate would be finished
171174
// see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61
172175
return;
173176
}
174-
taskStarted = false;
177+
taskStarted = null;
175178
progressDelegate.done();
176179
}
177180

@@ -196,7 +199,7 @@ public void setCanceled(boolean value) {
196199

197200
@Override
198201
public void setTaskName(String name) {
199-
if (!taskStarted) {
202+
if (taskStarted == null) {
200203
throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$
201204
}
202205
progressDelegate.setTaskName(name);
@@ -211,7 +214,7 @@ public void subTask(String name) {
211214

212215
@Override
213216
public void worked(int work) {
214-
if (!taskStarted) {
217+
if (taskStarted == null) {
215218
throw new IllegalStateException("call to beginTask() missing"); //$NON-NLS-1$
216219
}
217220
progressDelegate.worked(work);

0 commit comments

Comments
 (0)