harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r588158 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/ArrayList.java test/api/common/tests/api/java/util/ArrayListTest.java
Date Thu, 25 Oct 2007 07:54:10 GMT
Author: tellison
Date: Thu Oct 25 00:54:09 2007
New Revision: 588158

URL: http://svn.apache.org/viewvc?rev=588158&view=rev
Log:
Growing an ArrayList should not call size() method
to be compatible with RI behavior.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/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=588158&r1=588157&r2=588158&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 Thu
Oct 25 00:54:09 2007
@@ -334,7 +334,7 @@
 	}
 
 	private void growAtEnd(int required) {
-		int size = size();
+		int size = lastIndex - firstIndex;
 		if (firstIndex >= required - (array.length - lastIndex)) {
 			int newLast = lastIndex - firstIndex;
 			if (size > 0) {
@@ -363,7 +363,7 @@
 	}
 
 	private void growAtFront(int required) {
-		int size = size();
+		int size = lastIndex - firstIndex;
 		if (array.length - lastIndex + firstIndex >= required) {
 			int newFirst = array.length - size;
 			if (size > 0) {
@@ -394,7 +394,8 @@
 	}
 
 	private void growForInsert(int location, int required) {
-		int size = size(), increment = size / 2;
+		int size = lastIndex - firstIndex;
+		int increment = size / 2;
 		if (required > increment) {
             increment = required;
         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java?rev=588158&r1=588157&r2=588158&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java
Thu Oct 25 00:54:09 2007
@@ -19,11 +19,11 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.ConcurrentModificationException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import java.util.ConcurrentModificationException;
 import java.util.Vector;
 
 import tests.support.Support_ListTest;
@@ -544,8 +544,35 @@
         list.addAll(0, collection);
         assertEquals(14, list.size());
     }
-    
-    
+
+    public static class ArrayListExtend extends ArrayList {
+
+        private int size = 0;
+
+        public ArrayListExtend() {
+            super(10);
+        }
+
+        public boolean add(Object o) {
+            size++;
+            return super.add(o);
+        }
+
+        public int size() {
+            return size;
+        }
+    }
+
+    public void test_subclassing() {
+        ArrayListExtend a = new ArrayListExtend();
+        /*
+         * Regression test for subclasses that override size() (which used to
+         * cause an exception when growing 'a').
+         */
+        for (int i = 0; i < 100; i++) {
+            a.add(new Object());
+        }
+    }
     
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message