< prev index next >

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

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

*** 507,520 **** */ @Override public AbstractStringBuilder append(CharSequence s, int start, int end) { if (s == null) s = "null"; ! if ((start < 0) || (start > end) || (end > s.length())) ! throw new IndexOutOfBoundsException( ! "start " + start + ", end " + end + ", s.length() " ! + s.length()); int len = end - start; ensureCapacityInternal(count + len); if (s instanceof String) { ((String)s).getChars(start, end, value, count); } else { --- 507,525 ---- */ @Override public AbstractStringBuilder append(CharSequence s, int start, int end) { if (s == null) s = "null"; ! if ((start < 0) || (start > end) || (end > s.length())) { ! String msg = "start " + start + ", end " + end + ! ", s.length() " + s.length() ! if (s instanceof String) { ! throw new StringIndexOutOfBoundsException(msg); ! } else { ! throw new IndexOutOfBoundsException(msg); ! } ! } int len = end - start; ensureCapacityInternal(count + len); if (s instanceof String) { ((String)s).getChars(start, end, value, count); } else {
*** 1131,1151 **** public AbstractStringBuilder insert(int dstOffset, CharSequence s, int start, int end) { if (s == null) s = "null"; if ((dstOffset < 0) || (dstOffset > this.length())) ! throw new IndexOutOfBoundsException("dstOffset "+dstOffset); ! if ((start < 0) || (end < 0) || (start > end) || (end > s.length())) ! throw new IndexOutOfBoundsException( ! "start " + start + ", end " + end + ", s.length() " ! + s.length()); int len = end - start; ensureCapacityInternal(count + len); System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); for (int i=start; i<end; i++) value[dstOffset++] = s.charAt(i); count += len; return this; } /** --- 1136,1165 ---- public AbstractStringBuilder insert(int dstOffset, CharSequence s, int start, int end) { if (s == null) s = "null"; if ((dstOffset < 0) || (dstOffset > this.length())) ! throw new StringIndexOutOfBoundsException("dstOffset "+dstOffset); ! if ((start < 0) || (end < 0) || (start > end) || (end > s.length())) { ! String msg = "start " + start + ", end " + end + ! ", s.length() " + s.length(); ! if (s instanceof String) { ! throw new StringIndexOutOfBoundsException(msg); ! } else { ! throw new IndexOutOfBoundsException(msg); ! } ! } int len = end - start; ensureCapacityInternal(count + len); System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); + if (s instanceof String) { + ((String)s).getChars(start, end, value, dstOffset); + } else { for (int i=start; i<end; i++) value[dstOffset++] = s.charAt(i); + } count += len; return this; } /**
< prev index next >