RFR: 8294696 - BufferedInputStream.transferTo should drain buffer when mark set [v6]

Vladimir Sitnikov vsitnikov at openjdk.org
Wed Nov 29 05:58:24 UTC 2023


On Wed, 29 Nov 2023 05:48:58 GMT, Vladimir Sitnikov <vsitnikov at openjdk.org> wrote:

>> Markus KARG has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Alternative C + Arrays.copyOfRange()
>
> src/java.base/share/classes/java/io/BufferedInputStream.java line 612:
> 
>> 610:             if (avail > 0) {
>> 611:                 // Prevent poisoning and leaking of buf
>> 612:                 byte[] buffer = Arrays.copyOfRange(getBufIfOpen(), pos, count);
> 
> @mkarg , could you please clarify why you added `Arrays.copyOfRange` here?
> It seems to be an excessive copy that doesn't help much.
> 
> `buf` is `protected` in `BufferedInputStream`, so if someone really wants to get hold of the actual buffer, they can subclass `BufferedInputStream` and expose the buffer directly.
> What do you think of removing `copyOfRange`?

Buffer copy was not there before, and defensive copy was never present in `ByteArrayInputStream` as well: https://github.com/openjdk/jdk/blob/9a6ca233c7e91ffa2ce9451568b3be88ccd04504/src/java.base/share/classes/java/io/ByteArrayInputStream.java#L213

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

PR Review Comment: https://git.openjdk.org/jdk/pull/10525#discussion_r1408780382


More information about the core-libs-dev mailing list