Skip to content

Commit 46f1f51

Browse files
EcljpseB0Tjukzi
authored andcommitted
AccumulatingProgressMonitor: log warning like StatusLineManager
to get meaningfull stacktrace - as AccumulatingProgressMonitor uses asyncExec which does not reveal the caller of the method.
1 parent 06c30e8 commit 46f1f51

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import org.eclipse.core.runtime.IProgressMonitor;
2020
import org.eclipse.core.runtime.IStatus;
2121
import org.eclipse.core.runtime.ProgressMonitorWrapper;
22+
import org.eclipse.core.runtime.Status;
2223
import org.eclipse.jface.dialogs.Dialog;
24+
import org.eclipse.jface.util.Policy;
2325
import org.eclipse.swt.widgets.Display;
2426

2527
/**
@@ -56,6 +58,8 @@
5658

5759
private String currentTask = ""; //$NON-NLS-1$
5860

61+
private volatile Exception taskStarted;
62+
5963
private class Collector implements Runnable {
6064
private String taskName;
6165

@@ -140,6 +144,15 @@ public AccumulatingProgressMonitor(IProgressMonitor monitor, Display display) {
140144

141145
@Override
142146
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$
143156
synchronized (this) {
144157
collector = null;
145158
}
@@ -177,6 +190,13 @@ private void createCollector(String taskName, String subTask, double work) {
177190

178191
@Override
179192
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;
180200
synchronized (this) {
181201
collector = null;
182202
}

0 commit comments

Comments
 (0)