[jdk19] RFR: 8289601: SegmentAllocator::allocateUtf8String(String str) should be clarified for strings containing \0
Paul Sandoz
psandoz at openjdk.org
Tue Jul 5 17:45:32 UTC 2022
On Mon, 4 Jul 2022 13:01:34 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> This PR updates the spec and implementation to throw an `IllegalArgumentException` when an attempt is made to convert a Java string containing null characters to a C string.
>
> Testing: local run of the `jdk_foreign` test suite.
It's tempting to allow null/0 characters to pass through, truncating the string, given the rarity of such characters, but it could hide a nasty bug.
If performance becomes a really important issue we can make intrinsic and vectorize.
I think it is better to refer to the characters in the String, rather than refer to bytes of the UTF-8 encoding of that String e.g. throws if the string contains a null character (same for the exception message). We can explain in an API note why.
-------------
PR: https://git.openjdk.org/jdk19/pull/107
More information about the core-libs-dev
mailing list