changeset 2649:3b63e506b57e

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
author martin
date Tue, 03 Aug 2010 12:22:49 -0700
parents 2feeefb45a44
children 188f156148ea
files src/share/classes/java/lang/AbstractStringBuilder.java
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/AbstractStringBuilder.java	Tue Aug 03 09:55:29 2010 -0400
+++ b/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;