RFR: 8345186: Incorrect @throws doc for MemorySegment::getString

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Dec 3 13:31:48 UTC 2024


On Mon, 2 Dec 2024 14:08:14 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to correct errors in the `MemorySegment::getString` documentation.
> 
> There is a test in https://github.com/openjdk/jdk/pull/22451/files#diff-13a3535a65f1e0664e98bd2584196eb9d9a0ada951fd2dabfac8a484263235d8R271 that actually tests an Exception with the correct message is thrown if no null terminator can be found.

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1280:

> 1278:      *         largest string supported by the platform
> 1279:      * @throws IndexOutOfBoundsException if {@code offset < 0}
> 1280:      * @throws IndexOutOfBoundsException if no {@code '\0'} terminator is present in

Maybe we should say "string terminator" instead of `\0`. Because the specified byte sequence of the string terminator is charset specific. So maybe:

> if no string terminator (e.g. `\0`) is present ... The size of the string terminator depends on the selected charset (... follow with text from the previous javadoc ... )

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22488#discussion_r1865988515


More information about the core-libs-dev mailing list