-
Bug
-
Resolution: Fixed
-
P3
-
1.2.2
-
kestrel
-
sparc
-
solaris_2.6
-
Verified
Name: ksC84122 Date: 04/16/99
The javadoc for JDK 1.2.2 java.lang.StringBuffer.getChars(int srcBegin, int srcEnd,
char[] dst, int dstBegin) states:
----
Throws:
IndexOutOfBoundsException - if any of the following is true:
srcBegin is negative
the srcBegin argument is greater than the srcEnd argument.
srcEnd is greater than this.length(), the current length of this
string buffer.
dstBegin+srcEnd-srcBegin is greater than dst.length
----
java.lang.StringBuffer.getChars(int srcBegin, int srcEnd,
char[] dst, int dstBegin) behavior
is inconsistent with the javadoc in the following case:
getChars(x, x, dst, a) x - any integer, a > dst.length
This call returns silently, however it contradicts javadoc statement:
"Throws: IndexOutOfBoundsException if dstBegin+srcEnd-srcBegin is greater than dst.length"
Also, the call: getChars(x, x, dst, dst.length) should throw
IndexOutOfBoundsException for consistency purposes.
A test example which demonstrates this problem.
===== test47.java ========
public class test47 {
public static void main (String argv[]) {
StringBuffer sb = new StringBuffer("sample string buffer");
char dst[] = new char[30];
boolean failed = false;
int a[][] = {
{0, 0, dst.length},
{0, 0, dst.length + 1},
{0, 0, dst.length + 20},
{5, 5, dst.length},
{5, 5, dst.length + 1},
{5, 5, dst.length + 20}
};
for (int i = 0; i < a.length; i++) {
try {
sb.getChars(a[i][0], a[i][1], dst, a[i][2]);
failed = true;
System.out.println("failed for:" + a[i][0] + " " + a[i][1] + " " + a[i][2] );
} catch (IndexOutOfBoundsException iobe) { //OKAY
}
}
if (!failed) {
System.out.println("PASSED: OK.");
}
return;
}
}
========= Sample run (JDK1.2.2) ==========
#>java test47
failed for:0 0 30
failed for:0 0 31
failed for:0 0 50
failed for:5 5 30
failed for:5 5 31
failed for:5 5 50
======================================================================
- relates to
-
JDK-4272838 java.lang.StringBuffer.getChars() inconsistent with spec
-
- Resolved
-