RFR: 8297632: InputStream.transferTo() method should specify what the return value should be when the number of bytes transfered is larger than Long.MAX_VALUE

Alan Bateman alanb at openjdk.org
Tue Nov 29 08:32:20 UTC 2022


On Tue, 29 Nov 2022 00:56:58 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> `java.io.InputStream::transferTo` could conceivably return a negative value if the count of bytes transferred overflows a `long`. Modify the method to limit the number of bytes transferred to `Long.MAX_VALUE` per invocation.

InputStream.transferTo is specified to transfer "all bytes from this input stream" so changing it to do a "short write" is major change and also creates a big inconsistency with java.io methods such as OutputStream.write that write all bytes.

I think other options will need to be explored. We have this same issue in other APIs where they specify that they return Long.MAX_VALUE when the size is larger.

It is likely that some of the overrides will need attention too.

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

Changes requested by alanb (Reviewer).

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


More information about the core-libs-dev mailing list