Skip to content

Commit

Permalink
Unwind the exception causes with Java11Http#performConnect
Browse files Browse the repository at this point in the history
Currently there is a generic exception caught for all kind of errors but
as the execution is actually performed async this means that any
exception is already wrapped in an ExecutionException holding the real
cause.

This unwinds the different causes that an happen (e.g. cancel, timeout,
...) and finally checks if this is an ExecutionException from the async
operation-
  • Loading branch information
laeubi committed Feb 3, 2024
1 parent 28753b9 commit b2e12ce
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;

Expand Down Expand Up @@ -1006,11 +1008,26 @@ private IStatus performConnect(IProgressMonitor monitor) {
int ticks = 1;
monitor.beginTask(getRemoteFileURL().toString() + Messages.HttpClientRetrieveFileTransfer_CONNECTING_TASK_NAME, ticks);
try {
if (monitor.isCanceled())
throw newUserCancelledException();
if (monitor.isCanceled()) {
setDoneCanceled();
return Status.CANCEL_STATUS;
}
httpResponse = httpClient.sendAsync(httpRequest, BodyHandlers.ofInputStream());
responseCode = httpResponse.get(getConnectTimeout(),TimeUnit.MILLISECONDS).statusCode();
} catch (final Exception e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
setDoneCanceled();
return Status.CANCEL_STATUS;
} catch (CancellationException e) {
setDoneCanceled();
return Status.CANCEL_STATUS;
} catch (Exception e) {
if (e instanceof ExecutionException) {
Throwable cause = ((ExecutionException) e).getCause();
if (cause instanceof Exception) {
e = (Exception) cause;
}
}
Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "performConnect", e); //$NON-NLS-1$
if (!isDone()) {
setDoneException(e);
Expand Down

0 comments on commit b2e12ce

Please sign in to comment.