@@ -149,14 +149,17 @@ public IProgressMonitor getProgressMonitor() {
149
149
: new NullProgressMonitor ();
150
150
151
151
return new IProgressMonitor () {
152
- private volatile boolean taskStarted ;
152
+ private volatile Exception taskStarted ;
153
153
154
154
@ Override
155
155
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 );
158
160
}
159
- taskStarted = true ;
161
+ taskStarted = new IllegalStateException (
162
+ "beginTask(" + name + ", " + totalWork + ") was called here previously" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
160
163
// According to the IProgressMonitor javadoc beginTask() must only be called
161
164
// once on a given progress monitor instance.
162
165
// 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) {
165
168
166
169
@ Override
167
170
public void done () {
168
- if (! taskStarted ) {
171
+ if (taskStarted == null ) {
169
172
// ignore call to done() if beginTask() was not called!
170
173
// Otherwise an otherwise already started delegate would be finished
171
174
// see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61
172
175
return ;
173
176
}
174
- taskStarted = false ;
177
+ taskStarted = null ;
175
178
progressDelegate .done ();
176
179
}
177
180
@@ -196,7 +199,7 @@ public void setCanceled(boolean value) {
196
199
197
200
@ Override
198
201
public void setTaskName (String name ) {
199
- if (! taskStarted ) {
202
+ if (taskStarted == null ) {
200
203
throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
201
204
}
202
205
progressDelegate .setTaskName (name );
@@ -211,7 +214,7 @@ public void subTask(String name) {
211
214
212
215
@ Override
213
216
public void worked (int work ) {
214
- if (! taskStarted ) {
217
+ if (taskStarted == null ) {
215
218
throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
216
219
}
217
220
progressDelegate .worked (work );
0 commit comments