@@ -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