RFR: 8299015: Ensure that HttpResponse.BodySubscribers.ofFile writes all bytes

Jaikiran Pai jpai at openjdk.org
Tue Dec 20 10:24:53 UTC 2022


On Mon, 19 Dec 2022 14:02:41 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

> The implementation of `BodySubscribers.ofFile` does not correctly handle the case of a short gathering write. The write should be retried until all the bytes have been written to the underlying file.
> 
> This is generally not an issue that would occur very frequently, since the `IOV_MAX` is commonly 1024 on Mac/Linux, and 16 on Windows. However, it is clearly a bug, and should be fixed.

src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java line 284:

> 282:         @Override
> 283:         public void onNext(List<ByteBuffer> items) {
> 284:             int size = Utils.remaining(items, Integer.MAX_VALUE);

Hello Chris, are we intentionally limiting the `max` to `Integer.MAX_VALUE` here? This specific `Utils.remaining` will throw an `IllegalArgumentException` if the total `remaining` content across the `items` exceed that max value. If it is intentional to use this method, should we explicitly handle the `IAE` and rethrow it as `IOException`?

-------------

PR: https://git.openjdk.org/jdk/pull/11722


More information about the net-dev mailing list