From 39cdadfb6ac8db7c84cf3259802d1f6ab26df8bf Mon Sep 17 00:00:00 2001 From: Per Minborg Date: Wed, 4 Dec 2024 14:17:00 +0000 Subject: [PATCH] 8345186: Incorrect @throws doc for MemorySegment::getString Reviewed-by: mcimadamore, jvernee --- .../java/lang/foreign/MemorySegment.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java index cd38bd19227..024dfacb71b 100644 --- a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java +++ b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java @@ -1277,9 +1277,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl { * @throws IllegalArgumentException if the size of the string is greater than the * largest string supported by the platform * @throws IndexOutOfBoundsException if {@code offset < 0} - * @throws IndexOutOfBoundsException if {@code offset > byteSize() - (B + 1)}, where - * {@code B} is the size, in bytes, of the string encoded using UTF-8 charset - * {@code str.getBytes(StandardCharsets.UTF_8).length}) + * @throws IndexOutOfBoundsException if no string terminator (e.g. {@code '\0'}) is + * present in this segment between the given {@code offset} and the end of + * this segment. * @throws IllegalStateException if the {@linkplain #scope() scope} associated with * this segment is not {@linkplain Scope#isAlive() alive} * @throws WrongThreadException if this method is called from a thread {@code T}, @@ -1315,14 +1315,11 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl { * @throws IllegalArgumentException if the size of the string is greater than the * largest string supported by the platform * @throws IndexOutOfBoundsException if {@code offset < 0} - * @throws IndexOutOfBoundsException if {@code offset > byteSize() - (B + N)}, where: - * + * @throws IndexOutOfBoundsException if no string terminator (e.g. {@code '\0'}) is + * present in this segment between the given {@code offset} and the end of + * this segment. The byte size of the string terminator depends on the + * selected {@code charset}. For instance, this is 1 for + * {@link StandardCharsets#US_ASCII} and 2 for {@link StandardCharsets#UTF_16} * @throws IllegalStateException if the {@linkplain #scope() scope} associated with * this segment is not {@linkplain Scope#isAlive() alive} * @throws WrongThreadException if this method is called from a thread {@code T},