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 [v7]

Vladimir Sitnikov vsitnikov at openjdk.org
Thu Dec 14 20:23:56 UTC 2023


On Thu, 14 Dec 2023 19:22:18 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/SequenceInputStream.java line 249:
>> 
>>> 247:                         transferred = Math.addExact(transferred, in.transferTo(out));
>>> 248:                     } catch (ArithmeticException ignore) {
>>> 249:                         return Long.MAX_VALUE;
>> 
>> @bplb , this looks like a bug to me: once `transferred` reaches `Long.MAX_VALUE` the transfer loop will terminate and the transfer will stop even in the case there are more streams available in the sequence.
>> 
>> I think the proper code should be `transferred = Long.MAX_VALUE` instead of `return Long.MAX_VALUE` (and there should be no `if (transferred < Long.MAX_VALUE)` check)
>> 
>> What do you think?
>
>> What do you think?
> 
> I think that you are looking at an obsolete repository:
> 
> https://github.com/openjdk/jdk/blob/c328f9589ddc3a981a2c63801bd991f8e593e69f/src/java.base/share/classes/java/io/InputStream.java#L802

I mean SequenceInputStream, not the base class: https://github.com/openjdk/jdk/blob/c328f9589ddc3a981a2c63801bd991f8e593e69f/src/java.base/share/classes/java/io/SequenceInputStream.java#L249

Could you please double-check?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/11403#discussion_r1427231492


More information about the core-libs-dev mailing list