harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r812104 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java
Date Mon, 07 Sep 2009 12:18:55 GMT
Author: tellison
Date: Mon Sep  7 12:18:55 2009
New Revision: 812104

URL: http://svn.apache.org/viewvc?rev=812104&view=rev
Log:
Part of HARMONY-6336 (ArrayIndexOutOfBoundsException thrown without index information; generally
AIOBE is thrown without specifying the index)
Enhance exception messages for AbstractStringBuilder class.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java?rev=812104&r1=812103&r2=812104&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/AbstractStringBuilder.java
Mon Sep  7 12:18:55 2009
@@ -118,21 +118,23 @@
         count = newSize;
     }
 
-    final void append0(char chars[], int start, int length) {
-        if (chars == null) {
-            throw new NullPointerException();
-        }
-        // start + length could overflow, start/length maybe MaxInt
-        if (start >= 0 && 0 <= length && length <= chars.length
- start) {
-            int newSize = count + length;
-            if (newSize > value.length) {
-                enlargeBuffer(newSize);
-            }
-            System.arraycopy(chars, start, value, count, length);
-            count = newSize;
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
+    final void append0(char[] chars, int offset, int length) {
+        // Force null check of chars first!
+        if (offset > chars.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+        }
+        if (length < 0 || chars.length - offset < length) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
+
+        int newSize = count + length;
+        if (newSize > value.length) {
+            enlargeBuffer(newSize);
+        }
+        System.arraycopy(chars, offset, value, count, length);
+        count = newSize;
     }
 
     final void append0(char ch) {



Mime
View raw message