@@ -149,15 +149,29 @@ public IProgressMonitor getProgressMonitor() {
149
149
: new NullProgressMonitor ();
150
150
151
151
return new IProgressMonitor () {
152
+ private volatile boolean taskStarted ;
152
153
153
154
@ Override
154
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$
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.
155
163
progressDelegate .beginTask (name , totalWork );
156
-
157
164
}
158
165
159
166
@ Override
160
167
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 ;
161
175
progressDelegate .done ();
162
176
}
163
177
@@ -182,6 +196,9 @@ public void setCanceled(boolean value) {
182
196
183
197
@ Override
184
198
public void setTaskName (String name ) {
199
+ if (!taskStarted ) {
200
+ throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
201
+ }
185
202
progressDelegate .setTaskName (name );
186
203
187
204
}
@@ -194,6 +211,9 @@ public void subTask(String name) {
194
211
195
212
@ Override
196
213
public void worked (int work ) {
214
+ if (!taskStarted ) {
215
+ throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
216
+ }
197
217
progressDelegate .worked (work );
198
218
}
199
219
0 commit comments