# HG changeset patch # User chegar # Date 1528377710 -3600 # Node ID d219df0c7d2456a57ed62f586223d916631921ae # Parent 0b633bdb70109441ec5eeb8086e435b4453bd29e http-client-branch: synchronous send should be on the exception stack diff -r 0b633bdb7010 -r d219df0c7d24 src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java --- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java Thu Jun 07 10:45:30 2018 +0100 +++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java Thu Jun 07 14:21:50 2018 +0100 @@ -34,6 +34,7 @@ import java.net.Authenticator; import java.net.CookieHandler; import java.net.ProxySelector; +import java.net.http.HttpTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; @@ -518,18 +519,29 @@ send(HttpRequest req, BodyHandler responseHandler) throws IOException, InterruptedException { + CompletableFuture> cf = null; try { - return sendAsync(req, responseHandler, null, null).get(); + cf = sendAsync(req, responseHandler, null, null); + return cf.get(); + } catch (InterruptedException ie) { + if (cf != null ) + cf.cancel(true); + throw ie; } catch (ExecutionException e) { - Throwable t = e.getCause(); - if (t instanceof Error) - throw (Error)t; - if (t instanceof RuntimeException) - throw (RuntimeException)t; - else if (t instanceof IOException) - throw Utils.getIOException(t); + Throwable throwable = e.getCause(); + + if (throwable instanceof IllegalArgumentException) + throw new IllegalArgumentException(throwable); + else if (throwable instanceof SecurityException) + throw new SecurityException(throwable); + else if (throwable instanceof HttpTimeoutException) + throw new HttpTimeoutException(throwable.getMessage()); + else if (throwable instanceof IOException) + throw new IOException(throwable); + //else if (throwable instanceof UncheckedIOException) + // throw new UncheckedIOException(((UncheckedIOException)throwable).getCause()); else - throw new InternalError("Unexpected exception", t); + throw new IOException(throwable); } } diff -r 0b633bdb7010 -r d219df0c7d24 test/jdk/java/net/httpclient/ShortResponseBody.java --- a/test/jdk/java/net/httpclient/ShortResponseBody.java Thu Jun 07 10:45:30 2018 +0100 +++ b/test/jdk/java/net/httpclient/ShortResponseBody.java Thu Jun 07 14:21:50 2018 +0100 @@ -166,7 +166,7 @@ String msg = ioe.getMessage(); assertTrue(msg.contains(expectedMsg), "exception msg:[" + msg + "]"); // synchronous API must have the send method on the stack - //TODO: uncomment assertSendMethodOnStack(ioe); + assertSendMethodOnStack(ioe); assertNoConnectionExpiredException(ioe); } } @@ -232,7 +232,7 @@ // "incomplete" since the chunked request body is not completely sent assertTrue(msg.contains("incomplete"), "exception msg:[" + msg + "]"); // synchronous API must have the send method on the stack - //TODO: uncomment assertSendMethodOnStack(ioe); + assertSendMethodOnStack(ioe); assertNoConnectionExpiredException(ioe); } } diff -r 0b633bdb7010 -r d219df0c7d24 test/jdk/java/net/httpclient/ThrowingPublishers.java --- a/test/jdk/java/net/httpclient/ThrowingPublishers.java Thu Jun 07 10:45:30 2018 +0100 +++ b/test/jdk/java/net/httpclient/ThrowingPublishers.java Thu Jun 07 14:21:50 2018 +0100 @@ -345,8 +345,12 @@ try { response = client.send(req, handler); } catch (Error | Exception t) { - if (thrower.test(where, t)) { - System.out.println(now() + "Got expected exception: " + t); + // synchronous send will rethrow exceptions + Throwable throwable = t.getCause(); + assert throwable != null; + + if (thrower.test(where, throwable)) { + System.out.println(now() + "Got expected exception: " + throwable); } else throw causeNotFound(where, t); } } diff -r 0b633bdb7010 -r d219df0c7d24 test/jdk/java/net/httpclient/ThrowingSubscribers.java --- a/test/jdk/java/net/httpclient/ThrowingSubscribers.java Thu Jun 07 10:45:30 2018 +0100 +++ b/test/jdk/java/net/httpclient/ThrowingSubscribers.java Thu Jun 07 14:21:50 2018 +0100 @@ -409,8 +409,12 @@ try { response = client.send(req, handler); } catch (Error | Exception t) { - if (thrower.test(t)) { - System.out.println(now() + "Got expected exception: " + t); + // synchronous send will rethrow exceptions + Throwable throwable = t.getCause(); + assert throwable != null; + + if (thrower.test(throwable)) { + System.out.println(now() + "Got expected exception: " + throwable); } else throw causeNotFound(where, t); } }