diff -r 13588c901957 -r 9cf78a70fa4f src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java --- a/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java Thu Oct 17 20:27:44 2019 +0100 +++ b/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java Thu Oct 17 20:53:35 2019 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -59,7 +59,6 @@ private RequestPublishers() { } public static class ByteArrayPublisher implements BodyPublisher { - private volatile Flow.Publisher delegate; private final int length; private final byte[] content; private final int offset; @@ -99,7 +98,7 @@ @Override public void subscribe(Flow.Subscriber subscriber) { List copy = copy(content, offset, length); - this.delegate = new PullPublisher<>(copy); + var delegate = new PullPublisher<>(copy); delegate.subscribe(subscriber); } @@ -111,7 +110,6 @@ // This implementation has lots of room for improvement. public static class IterablePublisher implements BodyPublisher { - private volatile Flow.Publisher delegate; private final Iterable content; private volatile long contentLength; @@ -174,7 +172,7 @@ @Override public void subscribe(Flow.Subscriber subscriber) { Iterable iterable = this::iterator; - this.delegate = new PullPublisher<>(iterable); + var delegate = new PullPublisher<>(iterable); delegate.subscribe(subscriber); } @@ -271,12 +269,13 @@ @Override public void subscribe(Flow.Subscriber subscriber) { - InputStream is; + InputStream is = null; + Throwable t = null; if (System.getSecurityManager() == null) { try { is = new FileInputStream(file); } catch (IOException ioe) { - throw new UncheckedIOException(ioe); + t = ioe; } } else { try { @@ -284,11 +283,16 @@ () -> new FileInputStream(file); is = AccessController.doPrivileged(pa, null, filePermissions); } catch (PrivilegedActionException pae) { - throw new UncheckedIOException((IOException) pae.getCause()); + t = pae.getCause(); } } - PullPublisher publisher = - new PullPublisher<>(() -> new StreamIterator(is)); + final InputStream fis = is; + PullPublisher publisher; + if (t == null) { + publisher = new PullPublisher<>(() -> new StreamIterator(fis)); + } else { + publisher = new PullPublisher<>(null, t); + } publisher.subscribe(subscriber); }