RFR: 8369564: Provide a MemorySegment API to read strings with known lengths [v7]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Nov 20 11:40:14 UTC 2025
On Wed, 19 Nov 2025 20:34:21 GMT, ExE Boss <duke at openjdk.org> 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
More information about the core-libs-dev
mailing list