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

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Nov 21 17:29:12 UTC 2025


On Fri, 21 Nov 2025 14:36:44 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1333:
>> 
>>> 1331:      * sequences with this charset's default replacement string. The {@link
>>> 1332:      * java.nio.charset.CharsetDecoder} class should be used when more control
>>> 1333:      * over the decoding process is required.
>> 
>> Should we say here, as you did for `copy` that this method ignores `\0` ?
>
> I added:
> 
>> If the string contains any {@code '\0'} characters, they will be read as well.
> 
> I suppose it might also make sense to update those warnings in `setString` and `allocateFrom` to mention that if you want to avoid truncating null-terminated strings, `getString(long, Charset, long)` could be used instead of `getString(long)`. What do you think?

Could be a good idea, thanks!

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

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


More information about the core-libs-dev mailing list