CharBuffer.append(CharSequence csq, int start, int end) should throw an IndexOutOfBoundsException according to the specification of Appendable.append(CharSequence csq, int start, int end) which states the preconditions: 0 <= start <= end <= csq.length(). For example,
CharBuffer.allocate(7).append("12345678", 4, 12);
should throw an IndexOutOfBoundsException.
Specifically, in the current code, a BufferOverflowException is thrown if end - start > cb.remaining() without first checking the validity of start and end, which clearly should precede the overflow check as otherwise the indexes are not known to be valid. Throwing an IndexOutOfBoundsException also matches the behavior in JDK 20.
CharBuffer.allocate(7).append("12345678", 4, 12);
should throw an IndexOutOfBoundsException.
Specifically, in the current code, a BufferOverflowException is thrown if end - start > cb.remaining() without first checking the validity of start and end, which clearly should precede the overflow check as otherwise the indexes are not known to be valid. Throwing an IndexOutOfBoundsException also matches the behavior in JDK 20.
- relates to
-
JDK-8306623 (bf) CharBuffer::allocate throws unexpected exception type with some CharSequences
-
- Closed
-
-
JDK-8305811 (bf) Improve performance of CharBuffer::append(CharSequence[,int,int])
-
- Resolved
-
-
JDK-8306374 (bf) Improve performance of DirectCharBuffer::append(CharSequence[,int,int])
-
- Resolved
-