Skip to content

Commit

Permalink
8294008: Grapheme implementation of setText() throws IndexOutOfBounds…
Browse files Browse the repository at this point in the history
…Exception

Reviewed-by: joehw, smarks
  • Loading branch information
naotoj committed Sep 20, 2022
1 parent df8ec09 commit e3358e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -317,7 +317,15 @@ public boolean equals(Object o) {
}
}

// Implementation only for calling Grapheme.nextBoundary()
/**
* Implementation only for calling Grapheme.nextBoundary().
*
* 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. The calling
* code in GraphemeBreakIterator takes care to ensure that only valid indexes
* into the src are used.
*/
static final class CharacterIteratorCharSequence implements CharSequence {
CharacterIterator src;
CharacterIteratorCharSequence(CharacterIterator ci) {
Expand All @@ -326,7 +334,10 @@ static final class CharacterIteratorCharSequence implements CharSequence {

@Override
public int length() {
return src.getEndIndex() - src.getBeginIndex();
// Return the entire CharSequence length (0 to endIndex), not to
// be confused with the text range length (beginIndex to endIndex)
// of the underlying CharacterIterator.
return src.getEndIndex();
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions test/jdk/java/text/BreakIterator/BreakIteratorTest.java
Expand Up @@ -26,6 +26,7 @@
* @bug 4035266 4052418 4068133 4068137 4068139 4086052 4095322 4097779
* 4097920 4098467 4111338 4113835 4117554 4143071 4146175 4152117
* 4152416 4153072 4158381 4214367 4217703 4638433 8264765 8291660
* 8294008
* @library /java/text/testlib
* @run main/timeout=2000 BreakIteratorTest
* @summary test BreakIterator
Expand Down Expand Up @@ -1468,4 +1469,8 @@ public void TestGraphemeBreak() throws Exception {
generalIteratorTest(characterBreak, expected);
});
}

public void TestSetTextIOOBException() {
BreakIterator.getCharacterInstance().setText(new StringCharacterIterator("abcfefg", 1, 5, 3));
}
}

1 comment on commit e3358e7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.