On Wed, 17 Jun 2026 16:25:04 GMT, Naoto Sato <[email protected]> wrote:

>> 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.

I'm sorry to keep you waiting for so long. I just fixed it just now but I have 
no idea how/where I should add concrete test strings to 
test/jdk/java/nio/Buffer/CharBufferAsCharSequenceTest.java.

I have some ideas to test such an algorithm. I'm tfehe author of 
https://github.com/open-circle/valibot/issues/888, which is a similar PR for a 
famous JS validation library.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r3759321201

Reply via email to