RFR: 8299015: Ensure that HttpResponse.BodySubscribers.ofFile writes all bytes [v3]
Daniel Fuchs
dfuchs at openjdk.org
Tue Dec 20 10:42:27 UTC 2022
On Tue, 20 Dec 2022 10:33:22 GMT, Chris Hegarty <chegar at openjdk.org> wrote:
>> src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java line 289:
>>
>>> 287: ByteBuffer[] buffers = items.toArray(Utils.EMPTY_BB_ARRAY);
>>> 288: while (bytesWritten < size) {
>>> 289: bytesWritten += out.write(buffers);
>>
>> Should we handle the potential case of long value overflow, after addition here, which could then cause the while loop to misbehave?
>
> I replaced usages with Math::addExact, and generalised the catch to handle arithmetic exceptions too
That's the reason I originally didn't comment on the size limitation to Integer.MAX_VALUE - this is an acceptable limitation and it avoids to have to care about overflows here if size <= Integer.MAX_VALUE. Integer.MAX_VALUE shoudln't be reached in the context where the publisher is the HttpClient.
If we want to allow longs however, we should really use Math.addExact all the way down - including in Utils::remaining.
-------------
PR: https://git.openjdk.org/jdk/pull/11722
More information about the net-dev
mailing list