RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v5]
Alan Bateman
alanb at openjdk.org
Fri Dec 8 18:12:16 UTC 2023
On Fri, 8 Dec 2023 17:54:21 GMT, Vladimir Sitnikov <vsitnikov at openjdk.org> wrote:
>> src/java.base/share/classes/java/io/OutputStream.java line 212:
>>
>>> 210: * @return true if the argument of {@link #write(byte[])}} and {@link #write(byte[], int, int)}} needn't be copied
>>> 211: */
>>> 212: boolean trusted() {
>>
>> This is a strange construction. Any subclass could simply implement this as `return true;`. Where is the guard against this, and why not doing it that way?
>
> Technically speaking, `OutputStream` is an `abstract class`, so this declaration of `boolean trusted()` is a package-protected method that will be visible and overridable only within JDK itself.
> However, I agree it looks suspicious.
The comment on this method doesn't look right. The issue for BAIS is that its lifetime may be different to the byte[] that it wraps, think about use after the BAIS has been discarded. You don't want a sink keeping a reference to the byte[] even if it doesn't scribble on it.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1420861805
More information about the core-libs-dev
mailing list