Sean, Please roll this back until we get through the M12 vote. We are in code freeze. All commits require a second committer review until the freeze is over.
Thanks, Tim On 02/Dec/2009 03:44, [email protected] wrote: > Author: qiuxx > Date: Wed Dec 2 03:44:56 2009 > New Revision: 886043 > > URL: http://svn.apache.org/viewvc?rev=886043&view=rev > Log: > Apply 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=886043&r1=886042&r2=886043&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 > Wed Dec 2 03:44:56 2009 > @@ -1495,6 +1495,23 @@ > } > return equals((short[]) e1, (short[]) e2); > } > + > + private static boolean isSame(double double1, double double2) { > + // This method is required as Double.NaN == Double.NaN will return > false. > + long d1, d2; > + long NaNbits = Double.doubleToLongBits(Double.NaN); > + if ((d1 = Double.doubleToLongBits(double1)) == NaNbits) { > + if ((d2 = Double.doubleToLongBits(double2)) == NaNbits) { > + return true; > + } else { > + return false; > + } > + } else if ((d2 = Double.doubleToLongBits(double2)) == NaNbits) { > + return false; > + } else { > + return double1 == double2; > + } > + } > > private static boolean lessThan(double double1, double double2) { > // A slightly specialized version of > @@ -1896,7 +1913,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 +1921,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=886043&r1=886042&r2=886043&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 > Wed Dec 2 03:44:56 2009 > @@ -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[] { Double.NaN, 1.0, 2.0, Double.NaN, > + Double.NaN, 1.0, 3.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[] { 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)); > } > > /** > > >
