<i18n dev> RFR: 8294008: Grapheme implementation of setText() throws IndexOutOfBoundsException [v2]

Stuart Marks smarks at openjdk.org
Mon Sep 19 23:07:43 UTC 2022


On Mon, 19 Sep 2022 22:18:42 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> Yeah, I saw there's a mismatch between the src and limit in this call that led to the index check Exception:
>> 286             for (int b = ci.getBeginIndex(); b < end;) {
>> 287                 boundaries.add(b);
>> 288                 b = Grapheme.nextBoundary(text, b, end);
>> 289             }
>> 
>> and nextBoundary could walk through the entire CharSequence. Maybe it's worth a note to the length() method.
>
> Thanks, Joe. Added comment to the method.

OK yeah this is really confusing. One might ask a similar question in `charAt` about why it doesn't call

    src.setIndex(index + src.getBeginIndex());

The answer is that this is a special-purpose `CharSequence` that represents characters in the index range [0..endIndex) of the underlying `CharacterIterator`, **even if** that `CharacterIterator` represents the subrange of some string. As Joe noted, the calling code in `GraphemeBreakIterator` takes care to ensure that only valid indexes into the `src` are used.

I think the comment on `length` helps a little bit but maybe a class-level comment would be better, since it applies to the whole model of this special `CharSequence` and not just the `length` method. Just a sentence or two is sufficient. Feel free to crib from the above.

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

PR: https://git.openjdk.org/jdk/pull/10349


More information about the i18n-dev mailing list