Skip to content

Commit

Permalink
AccumulatingProgressMonitor: log warning like StatusLineManager
Browse files Browse the repository at this point in the history
to get meaningfull stacktrace - as AccumulatingProgressMonitor uses
asyncExec which does not reveal the caller of the method.
  • Loading branch information
EcljpseB0T authored and jukzi committed Sep 15, 2023
1 parent 06c30e8 commit 46f1f51
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.util.Policy;
import org.eclipse.swt.widgets.Display;

/**
Expand Down Expand Up @@ -56,6 +58,8 @@

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

private volatile Exception taskStarted;

private class Collector implements Runnable {
private String taskName;

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

@Override
public void beginTask(final String name, final int totalWork) {
if (taskStarted != null) {
Exception e = new IllegalStateException(
"beginTask should only be called once per instance. At least call done() before further invocations", //$NON-NLS-1$
taskStarted);
Policy.getLog().log(Status.warning(e.getLocalizedMessage(), e));
done(); // workaround client error
}
taskStarted = new IllegalStateException(
"beginTask(" + name + ", " + totalWork + ") was called here previously"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
synchronized (this) {
collector = null;
}
Expand Down Expand Up @@ -177,6 +190,13 @@ private void createCollector(String taskName, String subTask, double work) {

@Override
public void done() {
if (taskStarted == null) {
// ignore call to done() if beginTask() was not called!
// Otherwise an otherwise already started delegate would be finished
// see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/61
return;
}
taskStarted = null;
synchronized (this) {
collector = null;
}
Expand Down

0 comments on commit 46f1f51

Please sign in to comment.