On Mon, 3 Feb 2025 18:51:20 GMT, Shaojin Wen <s...@openjdk.org> wrote:

> The following code can reproduce the problem, writing out of bounds causes 
> JVM Crash
> 
> 
>          StringBuilder buf = new StringBuilder();
>         buf.append('δΈ­');
> 
>         Thread[] threads = new Thread[40];
>         final CountDownLatch latch = new CountDownLatch(threads.length);
>         Runnable r = () -> {
>             for (int i = 0; i < 1000000; i++) {
>                 buf.setLength(0);
>                 buf.trimToSize();
>                 buf.append(123456789123456789L);
>             }
>             latch.countDown();
>         };
> 
>         for (int i = 0; i < threads.length; i++) {
>             threads[i] = new Thread(r);
>         }
>         for (Thread t : threads) {
>             t.start();
>         }
>         latch.await();
> 
> 
> This problem can be avoided by using the value of ensureCapacityInternal 
> directly.

This pull request has been closed without being integrated.

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

PR: https://git.openjdk.org/jdk/pull/23427

Reply via email to