-
Bug
-
Resolution: Fixed
-
P4
-
1.1.4
-
1.1.6
-
sparc
-
solaris_2.5
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2016897 | 1.2.0 | Norbert Lindenberg | P4 | Resolved | Fixed | 1.2beta3 |
Name: mgC56079 Date: 09/11/97
The java.text.StringCharacterIterator.StringCharacterIterator(String text,
int begin, int end, int pos)
constructor does not check whether end > text.length().
It checks only whether 0<=begin<=pos<=end.
Should check for 0<=begin<=pos<=end<=text.length().
As a result a StringCharacterIterator may be created which has an invalid
state (the current() method will throw a StringIndexOutOfBoundsException).
------------------------- Here is the source --------------------------
------( No check whether end is larger than text.length() is done) ----
public StringCharacterIterator(String text, int begin, int end, int pos) {
if (text == null)
throw new NullPointerException();
this.text = text;
if (begin < 0 || begin > end)
throw new IllegalArgumentException("Invalid substring range");
if (pos < begin || pos > end)
throw new IllegalArgumentException("Invalid position");
this.begin = begin;
this.end = end;
this.pos = pos;
}
---------Here is the test demonstrating the bug (SCITest2.java) ----------
import java.text.StringCharacterIterator;
public class SCITest2 {
public static void main(String args[]) {
StringCharacterIterator sci =
new StringCharacterIterator("The string", 0, 100, 99);
System.out.print("Current char: ");
System.out.println(sci.current());
}
}
---------Output from the test---------------------
% java SCITest2
Current char: java.lang.StringIndexOutOfBoundsException: String index out of range: 99
at java.lang.String.charAt(String.java)
at java.text.StringCharacterIterator.current(StringCharacterIterator.java:174)
at SCITest2.main(SCITest2.java:8)
--------------------------------------------------
======================================================================
- backported by
-
JDK-2016897 java.text.StringCharacterIterator constructor allows large endIndexes
-
- Resolved
-