6955504: (str) String[Builder/Buffer].append(char[],int,int) throws OutOfMemoryError in b94
Summary: let arraycopy throw AIOOBE for invalid negative length
Reviewed-by: chegar, forax
--- a/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Tue Aug 03 09:55:29 2010 -0400
+++ b/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Tue Aug 03 12:22:49 2010 -0700
@@ -470,7 +470,7 @@
public AbstractStringBuilder append(CharSequence s, int start, int end) {
if (s == null)
s = "null";
- if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
+ if ((start < 0) || (start > end) || (end > s.length()))
throw new IndexOutOfBoundsException(
"start " + start + ", end " + end + ", s.length() "
+ s.length());
@@ -529,7 +529,8 @@
* or {@code offset+len > str.length}
*/
public AbstractStringBuilder append(char str[], int offset, int len) {
- ensureCapacityInternal(count + len);
+ if (len > 0) // let arraycopy report AIOOBE for len < 0
+ ensureCapacityInternal(count + len);
System.arraycopy(str, offset, value, count, len);
count += len;
return this;