-
Bug
-
Resolution: Fixed
-
P3
-
1.2.2
-
kestrel
-
sparc
-
solaris_2.6
-
Verified
Name: ksC84122 Date: 04/20/99
JDK 1.2.2 java.lang.StringBuffer.insert(int index, char str[], int offset, int len)
throws OutOfMemoryError or ArrayIndexOutOfBoundsExc when len == Integer.MAX_VALUE
or offset == Integer.MAX_VALUE.
This is a coding error when checking that "(offset+len) is greater than
str.length".
A test example which demonstrates this problem.
===== test49.java ========
public class test49 {
public static void main (String argv[]) {
StringBuffer sb = new StringBuffer("");
StringBuffer sb1 = new StringBuffer("Some test StringBuffer");
try {
sb.insert(0, new char[5], 1, Integer.MAX_VALUE);
System.out.println("CASE1 Failed: " +
"StringIndexOutOfBoundsException expected");
} catch (StringIndexOutOfBoundsException sobe) {
System.out.println("CASE1 Passed");
} catch (OutOfMemoryError oome) {
System.out.println("CASE1 Failed: unexpected" + oome);
}
try {
sb1.insert(2, new char[25], 5, Integer.MAX_VALUE);
System.out.println("CASE2 Failed: " +
"StringIndexOutOfBoundsException expected");
} catch (StringIndexOutOfBoundsException sobe) {
System.out.println("CASE2 Passed");
} catch (ArrayIndexOutOfBoundsException aioe) {
System.out.println("CASE2 Failed: unexpected " + aioe);
}
return;
}
}
========= Sample run (JDK1.2.2) ==========
>java test49
CASE1 Failed: unexpectedjava.lang.OutOfMemoryError
CASE2 Failed: unexpected java.lang.ArrayIndexOutOfBoundsException
======================================================================