harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r385541 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Vector.java test/java/org/apache/harmony/tests/java/util/AllTests.java test/java/org/apache/harmony/tests/java/util/VectorTest.java
Date Mon, 13 Mar 2006 13:09:54 GMT
Author: tellison
Date: Mon Mar 13 05:09:52 2006
New Revision: 385541

URL: http://svn.apache.org/viewcvs?rev=385541&view=rev
Log:
Fix Vector#toString() to work with self-referencing elements

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java?rev=385541&r1=385540&r2=385541&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Vector.java
Mon Mar 13 05:09:52 2006
@@ -940,15 +940,23 @@
 	 */
 	public synchronized String toString() {
 		if (elementCount == 0)
-			return "[]"; //$NON-NLS-1$
+			return "[]";
 		int length = elementCount - 1;
 		StringBuffer buffer = new StringBuffer(size() * 16);
 		buffer.append('[');
 		for (int i = 0; i < length; i++) {
-			buffer.append(elementData[i]);
-			buffer.append(", "); //$NON-NLS-1$
+			if (elementData[i] == this) {
+				buffer.append("(this Collection)");
+			} else {
+				buffer.append(elementData[i]);
+			}
+			buffer.append(", ");
+		}
+		if (elementData[length] == this) {
+			buffer.append("(this Collection)");
+		} else {
+			buffer.append(elementData[length]);
 		}
-		buffer.append(elementData[length]);
 		buffer.append(']');
 		return buffer.toString();
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/AllTests.java?rev=385541&r1=385540&r2=385541&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/AllTests.java
Mon Mar 13 05:09:52 2006
@@ -34,6 +34,7 @@
 		suite.addTestSuite(WeakHashMapTest.class);
 		suite.addTestSuite(IdentityHashMapTest.class);
 		suite.addTestSuite(DateTest.class);
+		suite.addTestSuite(VectorTest.class);
 		suite.addTestSuite(LocaleTest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java?rev=385541&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java
Mon Mar 13 05:09:52 2006
@@ -0,0 +1,35 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.util;
+
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+public class VectorTest extends TestCase {
+
+	/**
+	 * @tests java.util.Vector#toString()
+	 */
+	public void test_toString() {
+		// Ensure toString works with self-referencing elements.
+		Vector vec = new Vector(3);
+		vec.add(null);
+		vec.add(new Object());
+		vec.add(vec);
+		vec.toString();
+	}
+}



Mime
View raw message