Name: saf@russia Date: 08/21/96
This bug was found by St.Petersburg Java SQE team (by Mikhail Gorshenev).
The java.lang.String.startsWith method does not work with
large values of toffset parameter according to the
Java language specification.
The Java Language specification (Version 1.0, August 1, 1996)
says the following (please see item 20.12.21):
"20.12.21 public boolean startsWith(String prefix, int toffset)
throws NullPointerException
The result is true if and only if the character sequence represented by the
argument is a prefix of the substring of this String object starting at index
toffset.
If prefix is null, then a NullPointerException is thrown.
The result is false if toffset is negative or greater than the length of this
String object; otherwise, the result is the same as the result of the
expression
this.subString(toffset).startsWith(prefix)"
Here is the minimized test demonstrating the bug:
----- java_lang_String_startsWith.java ---------------------------------------
class java_lang_String_startsWith {
public static void main(String argv[]) {
try {
boolean b="some string".startsWith("other",Integer.MAX_VALUE);
if(!b)
System.out.println("Test passed: b = " + b);
else
System.out.println("Test failed: b = " + b);
} catch(Throwable e) {
System.out.println("Test failed: unexpected <"+e+"> is thrown");
}
}
}
----- The output of the test: -------------------------
Test failed: unexpected <java.lang.ArrayIndexOutOfBoundsException: 2147483647> is thrown
-------------------------------------------------------