> 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.
Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision: from @RogerRiggs ------------- Changes: - all: https://git.openjdk.org/jdk/pull/23427/files - new: https://git.openjdk.org/jdk/pull/23427/files/5f8a8d53..379ab3a8 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=23427&range=06 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=23427&range=05-06 Stats: 4 lines in 1 file changed: 1 ins; 1 del; 2 mod Patch: https://git.openjdk.org/jdk/pull/23427.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/23427/head:pull/23427 PR: https://git.openjdk.org/jdk/pull/23427