1616import org .eclipse .core .runtime .IProgressMonitor ;
1717import org .eclipse .core .runtime .IStatus ;
1818import org .eclipse .core .runtime .NullProgressMonitor ;
19+ import org .eclipse .core .runtime .Status ;
20+ import org .eclipse .jface .util .Policy ;
1921import org .eclipse .swt .SWT ;
2022import org .eclipse .swt .graphics .Image ;
2123import org .eclipse .swt .widgets .Composite ;
@@ -154,9 +156,13 @@ public IProgressMonitor getProgressMonitor() {
154156 @ Override
155157 public void beginTask (String name , int totalWork ) {
156158 if (taskStarted != null ) {
157- throw new IllegalStateException (
159+ /// TODO: maybe even logging is too much as long as every SubMonitor.convert()
160+ /// illegally calls beginTask as second time.
161+ Exception e = new IllegalStateException (
158162 "beginTask should only be called once per instance. At least call done() before further invocations" , //$NON-NLS-1$
159163 taskStarted );
164+ Policy .getLog ().log (Status .warning (e .getLocalizedMessage (), e ));
165+ done (); // workaround client error
160166 }
161167 taskStarted = new IllegalStateException (
162168 "beginTask(" + name + ", " + totalWork + ") was called here previously" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -199,9 +205,6 @@ public void setCanceled(boolean value) {
199205
200206 @ Override
201207 public void setTaskName (String name ) {
202- if (taskStarted == null ) {
203- throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
204- }
205208 progressDelegate .setTaskName (name );
206209
207210 }
@@ -215,7 +218,8 @@ public void subTask(String name) {
215218 @ Override
216219 public void worked (int work ) {
217220 if (taskStarted == null ) {
218- throw new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
221+ Exception e = new IllegalStateException ("call to beginTask() missing" ); //$NON-NLS-1$
222+ Policy .getLog ().log (Status .warning (e .getLocalizedMessage (), e ));
219223 }
220224 progressDelegate .worked (work );
221225 }
0 commit comments