harmony-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=447282
Log:
Patch applied for HARMONY-866(Arrays.binarySearch should always return -1 on empty array)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?view=diff&rev=447282&r1=447281&r2=447282
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
Sun Sep 17 23:37:25 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 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.
@@ -357,6 +357,9 @@
      */
     @SuppressWarnings("unchecked")
     public static int binarySearch(Object[] array, Object object) {
+        if (array.length == 0) {
+			return -1;
+		}
         Comparable<Object> key = (Comparable<Object>) object;
         int low = 0, mid = 0, high = array.length - 1, result = 0;
         while (low <= high) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java?view=diff&rev=447282&r1=447281&r2=447282
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
Sun Sep 17 23:37:25 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 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.
@@ -248,6 +248,12 @@
 	public void test_binarySearch$Ljava_lang_ObjectLjava_lang_Object() {
 		// Test for method int java.util.Arrays.binarySearch(java.lang.Object
 		// [], java.lang.Object)
+		assertEquals(
+				"Binary search succeeded for non-comparable value in empty array",
+				-1, Arrays.binarySearch(new Object[] {}, new Object()));
+		assertEquals(
+				"Binary search succeeded for comparable value in empty array",
+				-1, Arrays.binarySearch(new Object[] {}, new Integer(-1)));
 		for (int counter = 0; counter < arraySize; counter++)
 			assertTrue(
 					"Binary search on Object[] answered incorrect position",



Mime
View raw message