Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084738 | emb-9 | Xueming Shen | P2 | Resolved | Fixed | team |
As stated in javadocs this constructor must throw IndexOutOfBoundsException if the offset and length arguments index characters outside the bounds of the bytes array.
http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#String-byte:A-int-int-java.nio.charset.Charset-
In the following example the constructor is invoked with 3 elements in the array. Offset value is equal to 3, so it indexes the element which is out of bounds, as far as indexing starts with 0.
The expected behavior in this case is throwing the IndexOutOfBoundsException exception, but the empty string is formed instead. Nevertheless, the exception is thrown if the length (third parameter) is nonzero.
The following code must throw exception according to the spec but it does not:
new String(new byte[] { 9, 9, 9 }, 3, 0, Charset.defaultCharset());
JCK test which would be shipped with JCK8a (not present in JCK8) fails due to this issue:
api/java_lang/String/index2.html#CtorBytesOffsetLenCharset
http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#String-byte:A-int-int-java.nio.charset.Charset-
In the following example the constructor is invoked with 3 elements in the array. Offset value is equal to 3, so it indexes the element which is out of bounds, as far as indexing starts with 0.
The expected behavior in this case is throwing the IndexOutOfBoundsException exception, but the empty string is formed instead. Nevertheless, the exception is thrown if the length (third parameter) is nonzero.
The following code must throw exception according to the spec but it does not:
new String(new byte[] { 9, 9, 9 }, 3, 0, Charset.defaultCharset());
JCK test which would be shipped with JCK8a (not present in JCK8) fails due to this issue:
api/java_lang/String/index2.html#CtorBytesOffsetLenCharset
- backported by
-
JDK-8084738 (str spec) String(byte[], int, int, Charset) should be clearer when IndexOutOfBoundsException is thrown
-
- Resolved
-