On Wed, 19 Nov 2025 20:34:21 GMT, ExE Boss <[email protected]> wrote: >> src/java.base/share/classes/java/lang/String.java line 2019: >> >>> 2017: } >>> 2018: >>> 2019: boolean bytesCompatible(Charset charset, int srcIndex, int >>> numChars) { >> >> Surprisingly here we don't do anything for the case where the string is >> UTF16 and the target charset is also UTF16? > > The **UTF‑16** `Charset`s disallow unpaired surrogates, which **Java** > `String`s allow. > > So this can only return `true` for **UTF‑16** when the platform and charset > endianness match and the `String` doesn’t have any unpaired surrogates.
Yeah, tricky stuff -- we'll need to think more before changing this ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2545655612
