-
Bug
-
Resolution: Fixed
-
P1
-
1.0.2
-
1.1
-
sparc
-
solaris_2.5
-
Not verified
Name: saf@russia Date: 08/21/96
This bug was found by St.Petersburg Java SQE team (by Mikhail Gorshenev).
The java.lang.String(char[] data,int offset,int count) constructor
does not work with large values of offset+count according to the
Java language specification.
The Java Language specification (Version 1.0, August 1, 1996)
says the following (please see item 20.12.5):
20.12.5 public String(char[] data, int offset, int count)
throws NullPointerException,IndexOutOfBoundsException
This constructor initializes a newly created String object so that it
represents the sequence of characters currently contained in a subarray of
the character array argument. The offset argument is the index of the first
character of the subarray and the count argument specifies the length of the
subarray. The contents of the subarray are copied; subsequent modification
of the character array does not affect the newly created string.
If data is null, then a NullPointerException is thrown.
If offset is negative, or count is negative, or offset+count is larger than
data.length, then an IndexOutOfBoundsException is thrown.
Here is the minimized test demonstrating the bug:
----- java_lang_String_Ctor2.java ---------------------------------------
class java_lang_String_Ctor2 {
public static void main(String argv[]) {
char data[]={'a','b','c','d','e','f'};
try {
String s = new String(data,5,Integer.MAX_VALUE);
System.out.println("Test failed: String s = \\"" + s + "\\" created");
}
catch (IndexOutOfBoundsException e) {
System.out.println("Test passed: " + e);
}
}
}
----- The output of the test: -------------------------
java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java)
at java_lang_String_Ctor2.main(java_lang_String_Ctor2.java:5)
-------------------------------------------------------