Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize cause of some InterruptedExceptions #1301

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.ui.actions;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
Expand Down Expand Up @@ -103,20 +104,19 @@ protected abstract void execute(IProgressMonitor monitor)
@Override
public synchronized final void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
AtomicReference<InvocationTargetException> rethrownInvocationTargetException = new AtomicReference<>();
AtomicReference<InterruptedException> rethrownInterruptedException = new AtomicReference<>();
try {
IWorkspaceRunnable workspaceRunnable = pm -> {
try {
execute(pm);
} catch (InvocationTargetException e1) {
// Pass it outside the workspace runnable
iteHolder[0] = e1;
rethrownInvocationTargetException.set(e1);
} catch (InterruptedException e2) {
// Re-throw as OperationCanceledException, which will be
// caught and re-thrown as InterruptedException below.
throw new OperationCanceledException(e2.getMessage());
rethrownInterruptedException.set(e2);
}
// CoreException and OperationCanceledException are propagated
fedejeanne marked this conversation as resolved.
Show resolved Hide resolved
// CoreException and unchecked exceptions (e.g. OperationCanceledException) are
// propagated to the outer catch
};
// if we are in the UI thread, make sure we use progress monitor
// that spins event loop to allow processing of pending asyncExecs
Expand All @@ -137,9 +137,13 @@ public synchronized final void run(IProgressMonitor monitor)
interruptedException.initCause(e);
throw interruptedException;
}
// Re-throw the InvocationTargetException, if any occurred
if (iteHolder[0] != null) {
throw iteHolder[0];

// Re-throw any exceptions caught while running the IWorkspaceRunnable
if (rethrownInvocationTargetException.get() != null) {
throw rethrownInvocationTargetException.get();
}
if (rethrownInterruptedException.get() != null) {
throw rethrownInterruptedException.get();
}
}
@Override
Expand Down
Loading