On Wed, 17 Jun 2026 09:52:38 GMT, Tatsunori Uchino <[email protected]> wrote:
>> Does the suggested code have a bug? I think the code returns 2 for
>> "\ud800\udc00" The loop breaks before the last low surrogate.
>
> Concluded that `if (i >= lastIndex) break;` is harmful.
>
>
> for (int i = 0; i < lastIndex;) {
> if (Character.isHighSurrogate(charAt(i++))) {
> if (Character.isLowSurrogate(charAt(i))) {
> n--;
> i++;
> }
> }
> }
>
>
> should work as intended. `i` after `++`ed won't leave the range `[0,
> lastIndex]` (`[0, length)`) as long as `i < lestIndex` before `++`ed.
Yes, that will solve the bug. The same is true for X-Buffer.java.template. I'd
expect a test case for covering the case.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r3429813488