harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r379778 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Collections.java test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
Date Wed, 22 Feb 2006 14:18:41 GMT
Author: tellison
Date: Wed Feb 22 06:18:39 2006
New Revision: 379778

URL: http://svn.apache.org/viewcvs?rev=379778&view=rev
Log:
Fix for HARMONY-94 (java.util.Collections.binarySearch(List, Object, Comparator c) throws
NPE when c is null)

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/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/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?rev=379778&r1=379777&r2=379778&view=diff
==============================================================================
--- 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
Wed Feb 22 06:18:39 2006
@@ -1339,7 +1339,8 @@
 	 * @param object
 	 *            the element to find
 	 * @param comparator
-	 *            the Comparator
+	 *            the Comparator.  If the comparator is <code>null</code>
+	 *            then the search uses the objects' natural ordering. 
 	 * @return the non-negative index of the element, or a negative index which
 	 *         is the -index - 1 where the element would be inserted
 	 * 
@@ -1349,6 +1350,9 @@
 	 */
 	public static int binarySearch(List list, Object object,
 			Comparator comparator) {
+		if (comparator == null) {
+			return Collections.binarySearch(list, object);
+		} 
 		if (!(list instanceof RandomAccess)) {
 			ListIterator it = list.listIterator();
 			while (it.hasNext()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java?rev=379778&r1=379777&r2=379778&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
Wed Feb 22 06:18:39 2006
@@ -18,12 +18,26 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 public class CollectionsTest extends TestCase {
 
+	/**
+	 * @tests java.util.Collections#binarySearch(java.util.List,
+	 *        java.lang.Object, java.util.Comparator)
+	 */
+	public void test_binarySearchLjava_util_ListLjava_lang_ObjectLjava_util_Comparator() {
+		// Regression for HARMONY-94
+		LinkedList lst = new LinkedList();
+		lst.add(new Integer(30));
+		Collections.sort(lst, null);
+		int index = Collections.binarySearch(lst, new Integer(2), null);
+		assertEquals(-1, index);
+	} 
+	   
 	/**
 	 * @tests java.util.Collections#rotate(java.util.List, int)
 	 */



Mime
View raw message