< prev index next >

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Print this page
rev 12306 : [mq]: 8130646-AbstractStringBuilder-to-throw-StringIndexOutOfBoundsException


 493      * <i>k+start-n</i> in the argument {@code s}.
 494      * <p>
 495      * If {@code s} is {@code null}, then this method appends
 496      * characters as if the s parameter was a sequence containing the four
 497      * characters {@code "null"}.
 498      *
 499      * @param   s the sequence to append.
 500      * @param   start   the starting index of the subsequence to be appended.
 501      * @param   end     the end index of the subsequence to be appended.
 502      * @return  a reference to this object.
 503      * @throws     IndexOutOfBoundsException if
 504      *             {@code start} is negative, or
 505      *             {@code start} is greater than {@code end} or
 506      *             {@code end} is greater than {@code s.length()}
 507      */
 508     @Override
 509     public AbstractStringBuilder append(CharSequence s, int start, int end) {
 510         if (s == null)
 511             s = "null";
 512         if ((start < 0) || (start > end) || (end > s.length()))
 513             throw new IndexOutOfBoundsException(
 514                 "start " + start + ", end " + end + ", s.length() "
 515                 + s.length());
 516         int len = end - start;
 517         ensureCapacityInternal(count + len);
 518         if (s instanceof String) {
 519             ((String)s).getChars(start, end, value, count);
 520         } else {
 521             for (int i = start, j = count; i < end; i++, j++)
 522                 value[j] = s.charAt(i);
 523         }
 524         count += len;
 525         return this;
 526     }
 527 
 528     /**
 529      * Appends the string representation of the {@code char} array
 530      * argument to this sequence.
 531      * <p>
 532      * The characters of the array argument are appended, in order, to
 533      * the contents of this sequence. The length of this sequence




 493      * <i>k+start-n</i> in the argument {@code s}.
 494      * <p>
 495      * If {@code s} is {@code null}, then this method appends
 496      * characters as if the s parameter was a sequence containing the four
 497      * characters {@code "null"}.
 498      *
 499      * @param   s the sequence to append.
 500      * @param   start   the starting index of the subsequence to be appended.
 501      * @param   end     the end index of the subsequence to be appended.
 502      * @return  a reference to this object.
 503      * @throws     IndexOutOfBoundsException if
 504      *             {@code start} is negative, or
 505      *             {@code start} is greater than {@code end} or
 506      *             {@code end} is greater than {@code s.length()}
 507      */
 508     @Override
 509     public AbstractStringBuilder append(CharSequence s, int start, int end) {
 510         if (s == null)
 511             s = "null";
 512         if ((start < 0) || (start > end) || (end > s.length()))
 513             throw new StringIndexOutOfBoundsException(
 514                 "start " + start + ", end " + end + ", s.length() "
 515                 + s.length());
 516         int len = end - start;
 517         ensureCapacityInternal(count + len);
 518         if (s instanceof String) {
 519             ((String)s).getChars(start, end, value, count);
 520         } else {
 521             for (int i = start, j = count; i < end; i++, j++)
 522                 value[j] = s.charAt(i);
 523         }
 524         count += len;
 525         return this;
 526     }
 527 
 528     /**
 529      * Appends the string representation of the {@code char} array
 530      * argument to this sequence.
 531      * <p>
 532      * The characters of the array argument are appended, in order, to
 533      * the contents of this sequence. The length of this sequence


< prev index next >