harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r447285 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/TreeMap.java test/java/tests/api/java/util/TreeMapTest.java
Date Mon, 18 Sep 2006 06:41:13 GMT
Author: pyang
Date: Sun Sep 17 23:41:12 2006
New Revision: 447285

URL: http://svn.apache.org/viewvc?view=rev&rev=447285
Log:
Patch applied for HARMONY-780([classlib][util] unexpected ClassCastException for java.util.TreeMap.put(Object,
new Object))

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java?view=diff&rev=447285&r1=447284&r2=447285
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
Sun Sep 17 23:41:12 2006
@@ -1267,19 +1267,22 @@
 
 	private Entry<K, V> rbInsert(K object) {
 		int result = 0;
-		Comparable<K> key = null;
-		if (comparator == null) {
-            key = toComparable(object);
-        }
-		Entry<K, V> y = null, x = root;
-		while (x != null) {
-			y = x;
-			result = key != null ? key.compareTo(x.key) : comparator.compare(
-					object, x.key);
-			if (result == 0) {
-                return x;
-            }
-			x = result < 0 ? x.left : x.right;
+		Entry<K, V> y = null;
+		if (size != 0) {
+			Comparable<K> key = null;
+			if (comparator == null) {
+				key = toComparable(object);
+			}
+			Entry<K, V> x = root;
+			while (x != null) {
+				y = x;
+				result = key != null ? key.compareTo(x.key) : comparator
+						.compare(object, x.key);
+				if (result == 0) {
+					return x;
+				}
+				x = result < 0 ? x.left : x.right;
+			}
 		}
 
 		size++;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java?view=diff&rev=447285&r1=447284&r2=447285
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
Sun Sep 17 23:41:12 2006
@@ -324,7 +324,19 @@
 		Object o = new Object();
 		tm.put("Hello", o);
 		assertTrue("Failed to put mapping", tm.get("Hello") == o);
-
+		
+		// regression for Harmony-780
+		tm = new TreeMap();
+		assertNull(tm.put(new Object(), new Object()));
+		try {
+			tm.put(new Integer(1), new Object());
+			fail("should throw ClassCastException");
+		} catch (ClassCastException e) {
+			// expected
+		}
+		
+		tm = new TreeMap();
+		assertNull(tm.put(new Integer(1), new Object()));
 	}
 
 	/**



Mime
View raw message