harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r542810 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Vector.java test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
Date Wed, 30 May 2007 12:57:28 GMT
Author: tellison
Date: Wed May 30 05:57:26 2007
New Revision: 542810

URL: http://svn.apache.org/viewvc?view=rev&rev=542810
Log:
Vector#add(Object) should not delegate to addElement to avoid possible infinite recursion.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java?view=diff&rev=542810&r1=542809&r2=542810
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java Wed May
30 05:57:26 2007
@@ -149,8 +149,12 @@
      * @return true
      */
     @Override
-    public boolean add(E object) {
-        addElement(object);
+    public synchronized boolean add(E object) {
+        if (elementCount == elementData.length) {
+            growByOne();
+        }
+        elementData[elementCount++] = object;
+        modCount++;
         return true;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java?view=diff&rev=542810&r1=542809&r2=542810
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
Wed May 30 05:57:26 2007
@@ -22,15 +22,45 @@
 
 public class VectorTest extends TestCase {
 
-	/**
-	 * @tests java.util.Vector#toString()
-	 */
-	public void test_toString() {
-		// Ensure toString works with self-referencing elements.
-		Vector<Object> vec = new Vector<Object>(3);
-		vec.add(null);
-		vec.add(new Object());
-		vec.add(vec);
-		assertNotNull(vec.toString());
-	}
+    class SubVector<E> extends Vector<E> {
+
+        private static final long serialVersionUID = 1L;
+
+        public SubVector() {
+            super();
+        }
+
+        public synchronized boolean add(E obj) {
+            super.addElement(obj);
+            return true;
+        }
+
+        public synchronized void addElement(E obj) {
+            super.add(obj);
+        }
+
+        /**
+         * @tests java.util.Vector#add(Object)
+         */
+        @SuppressWarnings("nls")
+        public void test_add() {
+            SubVector<String> subvector = new SubVector<String>();
+            subvector.add("foo");
+            subvector.addElement("bar");
+            assertEquals("Expected two elements in vector", 2, subvector.size());
+        }
+
+    }
+
+    /**
+     * @tests java.util.Vector#toString()
+     */
+    public void test_toString() {
+        // Ensure toString works with self-referencing elements.
+        Vector<Object> vec = new Vector<Object>(3);
+        vec.add(null);
+        vec.add(new Object());
+        vec.add(vec);
+        assertNotNull(vec.toString());
+    }
 }



Mime
View raw message