On Tue, 23 Apr 2024 16:08:13 GMT, Alan Bateman <[email protected]> wrote:
>> src/java.base/share/classes/java/io/ByteArrayOutputStream.java line 164:
>>
>>> 162: public void writeTo(OutputStream out) throws IOException {
>>> 163: if (Thread.currentThread().isVirtual()) {
>>> 164: out.write(toByteArray());
>>
>> Would it be better to avoid calling a public method `toByteArray` encase
>> subclass is overriding it?
>
> A good question. The buf/count fields are protected so the subclass has
> direct access to the bytes. So while it could Arrays.copy the bytes, it
> doesn't help with a buggy subclass that is changing bytes while
> synchronization.
I was thinking more of a subclass that counted invocations to public methods or
metering which would cause subclass to double the counts when calling via
virtual thread.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1576637177