harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r896060 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Arrays.java test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
Date Tue, 05 Jan 2010 14:21:00 GMT
Author: tellison
Date: Tue Jan  5 14:21:00 2010
New Revision: 896060

URL: http://svn.apache.org/viewvc?rev=896060&view=rev
Log:
Apply patch for HARMONY-6395 ([classlib][luni] Arrays.sort(double []) will result in StackOverflowError
for specific arrays input)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?rev=896060&r1=896059&r2=896060&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java Tue Jan
 5 14:21:00 2010
@@ -1496,6 +1496,26 @@
         return equals((short[]) e1, (short[]) e2);
     }
 
+    private static boolean isSame(double double1, double double2) {
+        // Simple case
+        if (double1 == double2 && 0.0d != double1) {
+            return true;
+        }
+
+        // Deal with NaNs
+        if (Double.isNaN(double1)) {
+            return Double.isNaN(double2);
+        }
+        if (Double.isNaN(double2)) {
+            return false;
+        }
+
+        // Deal with +0.0 and -0.0
+        long d1 = Double.doubleToRawLongBits(double1);
+        long d2 = Double.doubleToRawLongBits(double2);
+        return d1 == d2;
+    }
+
     private static boolean lessThan(double double1, double double2) {
         // A slightly specialized version of
         // Double.compare(double1, double2) < 0.
@@ -1524,6 +1544,26 @@
         return d1 < d2;
     }
 
+    private static boolean isSame(float float1, float float2) {
+        // Simple case
+        if (float1 == float2 && 0.0d != float1) {
+            return true;
+        }
+
+        // Deal with NaNs
+        if (Float.isNaN(float1)) {
+            return Float.isNaN(float2);
+        }
+        if (Float.isNaN(float2)) {
+            return false;
+        }
+
+        // Deal with +0.0 and -0.0
+        int f1 = Float.floatToRawIntBits(float1);
+        int f2 = Float.floatToRawIntBits(float2);
+        return f1 == f2;
+    }
+    
     private static boolean lessThan(float float1, float float2) {
         // A slightly specialized version of Float.compare(float1, float2) < 0.
 
@@ -1896,7 +1936,7 @@
         c = d = end - 1;
         while (true) {
             while (b <= c && !lessThan(partionValue, array[b])) {
-                if (array[b] == partionValue) {
+                if (isSame(array[b], partionValue)) {
                     temp = array[a];
                     array[a++] = array[b];
                     array[b] = temp;
@@ -1904,7 +1944,7 @@
                 b++;
             }
             while (c >= b && !lessThan(array[c], partionValue)) {
-                if (array[c] == partionValue) {
+                if (isSame(array[c], partionValue)) {
                     temp = array[c];
                     array[c] = array[d];
                     array[d--] = temp;
@@ -2009,7 +2049,7 @@
         c = d = end - 1;
         while (true) {
             while (b <= c && !lessThan(partionValue, array[b])) {
-                if (array[b] == partionValue) {
+                if (isSame(array[b], partionValue)) {
                     temp = array[a];
                     array[a++] = array[b];
                     array[b] = temp;
@@ -2017,7 +2057,7 @@
                 b++;
             }
             while (c >= b && !lessThan(array[c], partionValue)) {
-                if (array[c] == partionValue) {
+                if (isSame(array[c], partionValue)) {
                     temp = array[c];
                     array[c] = array[d];
                     array[d--] = temp;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java?rev=896060&r1=896059&r2=896060&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
Tue Jan  5 14:21:00 2010
@@ -911,9 +911,13 @@
 		double[] specials2 = new double[] { 0d, Double.POSITIVE_INFINITY, -0d,
 				Double.NEGATIVE_INFINITY, Double.MIN_VALUE, Double.NaN,
 				Double.MAX_VALUE };
+        double[] specials3 = new double[] { 0.0, Double.NaN, 1.0, 2.0, Double.NaN,
+                Double.NaN, 1.0, 3.0, -0.0};
 		double[] answer = new double[] { Double.NEGATIVE_INFINITY, -0d, 0d,
 				Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY,
 				Double.NaN };
+        double[] answer3 = new double[] { -0.0, 0.0, 1.0, 1.0, 2.0, 3.0, Double.NaN,
+                Double.NaN, Double.NaN };
 
 		Arrays.sort(specials1);
 		Object[] print1 = new Object[specials1.length];
@@ -928,6 +932,13 @@
 			print2[i] = new Double(specials2[i]);
 		assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
 				Arrays.equals(specials2, answer));
+        
+        Arrays.sort(specials3);
+        Object[] print3 = new Object[specials3.length];
+        for (int i = 0; i < specials3.length; i++)
+            print3[i] = new Double(specials3[i]);
+        assertTrue("specials sort incorrectly 3: " + Arrays.asList(print3),
+                Arrays.equals(specials3, answer3));
 	}
 
 	/**



Mime
View raw message