RFR: 8330748: ByteArrayOutputStream.writeTo(OutputStream) pins carrier [v2]
Brian Burkhalter
bpb at openjdk.org
Wed Apr 24 14:57:30 UTC 2024
On Wed, 24 Apr 2024 07:08:20 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> So do we think it better not to invoke `toByteArray` here?
>
> Using a subclass to count the number of invocations of toByteArray seems a bit strange but in general it is more robust to not rely on a method that may be overridden by a subclass. So I think the suggestion is good.
Currently we have
public void writeTo(OutputStream out) throws IOException {
if (Thread.currentThread().isVirtual()) {
out.write(toByteArray());
} else synchronized (this) {
out.write(buf, 0, count);
}
}
where `toByteArray()` is `synchronized`, but here I would think that we'd want to replace it with simply `Arrays.copyOf(buf, count)` without the `synchronized`, no?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1578031656
More information about the core-libs-dev
mailing list