RFR: 8369564: Provide a MemorySegment API to read strings with known lengths [v7]

ExE Boss duke at openjdk.org
Wed Nov 19 20:39:09 UTC 2025


On Wed, 19 Nov 2025 14:44:39 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add a dstOffset parameter, stop using StringCharBuffer/CharsetEncoder::encode
>
> 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.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2543486247


More information about the core-libs-dev mailing list