8289601: SegmentAllocator::allocateUtf8String(String str) should be clarified for strings containing \0

Reviewed-by: psandoz, mcimadamore
This commit is contained in:
Jorn Vernee 2022-07-08 15:21:11 +00:00
parent 732f1065fe
commit 460d879a75
2 changed files with 11 additions and 0 deletions

View file

@ -737,6 +737,12 @@ public sealed interface MemorySegment extends Addressable permits AbstractMemory
* sequences with this charset's default replacement string. The {@link
* java.nio.charset.CharsetDecoder} class should be used when more control
* over the decoding process is required.
* <p>
* If the given string contains any {@code '\0'} characters, they will be
* copied as well. This means that, depending on the method used to read
* the string, such as {@link MemorySegment#getUtf8String(long)}, the string
* will appear truncated when read again.
*
* @param offset offset in bytes (relative to this segment). For instance, if this segment is a {@linkplain #isNative() native} segment,
* the final address of this write operation can be expressed as {@code address().toRowLongValue() + offset}.
* @param str the Java string to be written into this segment.

View file

@ -71,6 +71,11 @@ public interface SegmentAllocator {
* sequences with this charset's default replacement byte array. The
* {@link java.nio.charset.CharsetEncoder} class should be used when more
* control over the encoding process is required.
* <p>
* If the given string contains any {@code '\0'} characters, they will be
* copied as well. This means that, depending on the method used to read
* the string, such as {@link MemorySegment#getUtf8String(long)}, the string
* will appear truncated when read again.
*
* @implSpec the default implementation for this method copies the contents of the provided Java string
* into a new memory segment obtained by calling {@code this.allocate(str.length() + 1)}.