harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r443309 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Collections.java test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
Date Thu, 14 Sep 2006 10:48:49 GMT
Author: hindessm
Date: Thu Sep 14 03:48:45 2006
New Revision: 443309

URL: http://svn.apache.org/viewvc?view=rev&rev=443309
Log:
Applied patch from "[#HARMONY-1367] [classlib][util] unexpected
ClassCastException for Collections.binarySearch(..)".

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?view=diff&rev=443309&r1=443308&r2=443309
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
Thu Sep 14 03:48:45 2006
@@ -1411,6 +1411,10 @@
 		if (list == null) {
             throw new NullPointerException();
         }
+		if(list.isEmpty()){
+			return -1;
+		}
+		
 		Comparable<T> key = (Comparable<T>)object;
 		if (!(list instanceof RandomAccess)) {
 			ListIterator<T> it = (ListIterator<T>)list.listIterator();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java?view=diff&rev=443309&r1=443308&r2=443309
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
Thu Sep 14 03:48:45 2006
@@ -61,6 +61,23 @@
 		int index = Collections.binarySearch(lst, new Integer(2), null);
 		assertEquals(-1, index);
 	} 
+	
+	/**
+	 * @tests java.util.Collections#binarySearch(java.util.List,
+	 *        java.lang.Object)
+	 */
+	public void test_binarySearchLjava_util_ListLjava_lang_Object() {
+		// regression for Harmony-1367
+		List localList = new LinkedList();
+		assertEquals(-1, Collections.binarySearch(localList, new Object()));
+		localList.add(new Object());
+		try {
+			Collections.binarySearch(localList, new Integer(1));
+			fail("Should throw ClassCastException");
+		} catch (ClassCastException e) {
+			// expected
+		}
+	}
 	   
 	/**
 	 * @tests java.util.Collections#rotate(java.util.List, int)



Mime
View raw message