Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8306959

(bf) CharBuffer.append(CharSequence,int,int) throws BufferOverflowException where IndexOutOfBoundsException expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • 21
    • core-libs
    • None
    • 21
    • b21
    • generic
    • generic

      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.

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: