|
19 | 19 | import org.eclipse.core.runtime.IProgressMonitor;
|
20 | 20 | import org.eclipse.core.runtime.IStatus;
|
21 | 21 | import org.eclipse.core.runtime.ProgressMonitorWrapper;
|
| 22 | +import org.eclipse.core.runtime.Status; |
22 | 23 | import org.eclipse.jface.dialogs.Dialog;
|
| 24 | +import org.eclipse.jface.util.Policy; |
23 | 25 | import org.eclipse.swt.widgets.Display;
|
24 | 26 |
|
25 | 27 | /**
|
|
56 | 58 |
|
57 | 59 | private String currentTask = ""; //$NON-NLS-1$
|
58 | 60 |
|
| 61 | + private volatile Exception taskStarted; |
| 62 | + |
59 | 63 | private class Collector implements Runnable {
|
60 | 64 | private String taskName;
|
61 | 65 |
|
@@ -140,6 +144,15 @@ public AccumulatingProgressMonitor(IProgressMonitor monitor, Display display) {
|
140 | 144 |
|
141 | 145 | @Override
|
142 | 146 | public void beginTask(final String name, final int totalWork) {
|
| 147 | + if (taskStarted != null) { |
| 148 | + Exception e = new IllegalStateException( |
| 149 | + "beginTask should only be called once per instance. At least call done() before further invocations", //$NON-NLS-1$ |
| 150 | + taskStarted); |
| 151 | + Policy.getLog().log(Status.warning(e.getLocalizedMessage(), e)); |
| 152 | + done(); // workaround client error |
| 153 | + } |
| 154 | + taskStarted = new IllegalStateException( |
| 155 | + "beginTask(" + name + ", " + totalWork + ") was called here previously"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
143 | 156 | synchronized (this) {
|
144 | 157 | collector = null;
|
145 | 158 | }
|
@@ -177,6 +190,13 @@ private void createCollector(String taskName, String subTask, double work) {
|
177 | 190 |
|
178 | 191 | @Override
|
179 | 192 | public void done() {
|
| 193 | + if (taskStarted == null) { |
| 194 | + // ignore call to done() if beginTask() was not called! |
| 195 | + // Otherwise an otherwise already started delegate would be finished |
| 196 | + // see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61 |
| 197 | + return; |
| 198 | + } |
| 199 | + taskStarted = null; |
180 | 200 | synchronized (this) {
|
181 | 201 | collector = null;
|
182 | 202 | }
|
|
0 commit comments