harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r647083 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/ArrayList.java test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
Date Fri, 11 Apr 2008 09:09:20 GMT
Author: tonywu
Date: Fri Apr 11 02:09:15 2008
New Revision: 647083

URL: http://svn.apache.org/viewvc?rev=647083&view=rev
Log:
Apply patch for HARMONY-5705 ([classlib][luni] ArrayList.addAll( Collection c) may throw unexpected
ArrayIndexOutofBoundsException)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java?rev=647083&r1=647082&r2=647083&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java Fri
Apr 11 02:09:15 2008
@@ -224,19 +224,17 @@
      */
     @Override
     public boolean addAll(Collection<? extends E> collection) {
-        int growSize = collection.size();
-        if (growSize > 0) {
-            if (lastIndex > array.length - growSize) {
-                growAtEnd(growSize);
-            }
-            Object[] dumparray = new Object[growSize];
-            collection.toArray(dumparray);
-            System.arraycopy(dumparray, 0, this.array, lastIndex, growSize);
-            lastIndex += growSize;
-            modCount++;
-            return true;
-        }
-        return false;
+        Object[] dumpArray = collection.toArray();
+        if (dumpArray.length == 0) {
+            return false;
+        }
+        if (dumpArray.length > array.length - lastIndex) {
+            growAtEnd(dumpArray.length);
+        }
+        System.arraycopy(dumpArray, 0, this.array, lastIndex, dumpArray.length);
+        lastIndex += dumpArray.length;
+        modCount++;
+        return true;
     }
 
     /**
@@ -520,6 +518,9 @@
                             elementIndex, size - location - 1);
                     array[--lastIndex] = null;
                 }
+            }
+            if (firstIndex == lastIndex) {
+                firstIndex = lastIndex = 0;
             }
         } else {
             throw new IndexOutOfBoundsException();

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java?rev=647083&r1=647082&r2=647083&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
Fri Apr 11 02:09:15 2008
@@ -154,6 +154,31 @@
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException e) {
         }
+        
+        // Regression for HARMONY-5705
+        String[] data = new String[] { "1", "2", "3", "4", "5", "6", "7", "8" };
+        ArrayList list1 = new ArrayList();
+        ArrayList list2 = new ArrayList();
+        for (String d : data) {
+            list1.add(d);
+            list2.add(d);
+            list2.add(d);
+        }
+        while (list1.size() > 0)
+            list1.remove(0);
+        list1.addAll(list2);
+        assertTrue("The object list is not the same as orginal list", list1
+                .containsAll(list2) && list2.containsAll(list1));
+
+        obj = new ArrayList();
+        for (int i = 0; i < 100; i++) {
+            if (list1.size() > 0) {
+                obj.removeAll(list1);
+                obj.addAll(list1);
+            }
+        }
+        assertTrue("The object list is not the same as orginal list", obj
+                .containsAll(list1) && list1.containsAll(obj));
     }
 
     public void test_addAllCollectionOfQextendsE() {



Mime
View raw message