ICU-23124 Fix exception type in BreakIterator for OOB index values
diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java b/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java index f5f43bb..e8ed116 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java
@@ -524,12 +524,12 @@ public int preceding(int offset) { /** - * Throw IllegalArgumentException unless begin <= offset < end. + * Throw IndexOutOfBoundsException unless begin <= offset < end. * @stable ICU 2.0 */ protected static final void checkOffset(int offset, CharacterIterator text) { if (offset < text.getBeginIndex() || offset > text.getEndIndex()) { - throw new IllegalArgumentException("offset out of bounds"); + throw new IndexOutOfBoundsException("offset out of bounds"); } }
diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/BreakIteratorTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/BreakIteratorTest.java index f246ab4..e014e1e 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/BreakIteratorTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/BreakIteratorTest.java
@@ -158,7 +158,7 @@ public void TestBug4153072() { errln("Didn't get exception with offset = " + index + " and begin index = " + begin); } - catch (IllegalArgumentException e) { + catch (IndexOutOfBoundsException e) { if (index >= begin) errln("Got exception with offset = " + index + " and begin index = " + begin);