8216498: Confusing and unneeded wrapping of SSLHandshakeException

[httpclient] Avoid wrapping SSLHandshakeException in plain IOException

Reviewed-by: chegar
This commit is contained in:
Daniel Fuchs 2019-01-11 14:48:19 +00:00
parent 608258ffd1
commit 6627b03332
3 changed files with 51 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@
package jdk.internal.net.http;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLParameters;
import java.io.IOException;
import java.io.UncheckedIOException;
@ -561,6 +563,15 @@ final class HttpClientImpl extends HttpClient implements Trackable {
ConnectException ce = new ConnectException(msg);
ce.initCause(throwable);
throw ce;
} else if (throwable instanceof SSLHandshakeException) {
// special case for SSLHandshakeException
SSLHandshakeException he = new SSLHandshakeException(msg);
he.initCause(throwable);
throw he;
} else if (throwable instanceof SSLException) {
// any other SSLException is wrapped in a plain
// SSLException
throw new SSLException(msg, throwable);
} else if (throwable instanceof IOException) {
throw new IOException(msg, throwable);
} else {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,11 +31,11 @@ import sun.net.www.HeaderParser;
import javax.net.ssl.ExtendedSSLSession;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UncheckedIOException;
@ -74,7 +74,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import jdk.internal.net.http.HttpRequestImpl;
@ -307,11 +306,16 @@ public final class Utils {
if (!(t instanceof IOException))
return t;
if (t instanceof SSLHandshakeException)
return t; // no need to decorate
String msg = messageSupplier.get();
if (msg == null)
return t;
if (t instanceof ConnectionExpiredException) {
if (t.getCause() instanceof SSLHandshakeException)
return t; // no need to decorate
IOException ioe = new IOException(msg, t.getCause());
t = new ConnectionExpiredException(ioe);
} else {