On Fri, 14 Aug 2026 13:58:59 GMT, Tatsunori Uchino <[email protected]> wrote:
>> Adds `codePointCount()` overloads to `String`, `Character`,
>> `(Abstract)StringBuilder`, and `StringBuffer` to make it possible to
>> conveniently retrieve the length of a string as code points without extra
>> boundary checks.
>>
>>
>> if (superTremendouslyLongExpressionYieldingAString().codePointCount() >
>> limit) {
>> throw new Exception("exceeding length");
>> }
>>
>>
>> Is a CSR required to this change?
>>
>> - [x] I confirm that I make this contribution in accordance with the
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Tatsunori Uchino has updated the pull request incrementally with one
> additional commit since the last revision:
>
> Change "isolated surrogate code unit" to "unpaired surrogate"
test/jdk/java/lang/String/Supplementary.java line 406:
> 404: result, expected);
> 405: // Create a substring of the text range. It shares the
> 406: // underlying char[] of the String str.
I'd suggest removing these two comment lines. They seem to refer to an old
implementation of `String` where a substring shared the `char[]` from it's
"parent" string. That hasn't been true for a long time.
test/jdk/java/lang/String/Supplementary.java line 410:
> 408: result = substr.codePointCount(0, substr.length());
> 409: check(result != expected,
> "substring:codePointCount(input["+i+"], "+j+", "+length+")",
> 410: result, expected);
Per my comment in the main portion of the PR, add a call to the new no-arg
`substr.codePointCount()` and add a new call to `check`. And also do something
similar at the end of the for-loop below.
test/jdk/java/lang/String/Supplementary.java line 426:
> 424: int expected = Character.codePointCount(str, 0,
> str.length());
> 425: check(result != expected, "substring:codePointCount()",
> result, expected);
> 426:
I would move these new lines up toward the top of this method since it's an
obvious case that seems like it ought to be checked first. Before the first
for-loop is a good place. The `length` local variable can also be used instead
of `str.length()` and its meaning is clear since the local variable
initialization will be immediately above.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r3826342451
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r3826349333
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r3826339030