8330748: ByteArrayOutputStream.writeTo(OutputStream) pins carrier

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2024-04-29 17:54:13 +00:00
parent eb88343fb7
commit 819f3d6fc7
2 changed files with 142 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -159,8 +159,16 @@ public class ByteArrayOutputStream extends OutputStream {
* @throws NullPointerException if {@code out} is {@code null}.
* @throws IOException if an I/O error occurs.
*/
public synchronized void writeTo(OutputStream out) throws IOException {
out.write(buf, 0, count);
public void writeTo(OutputStream out) throws IOException {
if (Thread.currentThread().isVirtual()) {
byte[] bytes;
synchronized (this) {
bytes = Arrays.copyOf(buf, count);
}
out.write(bytes);
} else synchronized (this) {
out.write(buf, 0, count);
}
}
/**