You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2009/12/02 04:44:56 UTC

svn commit: r886043 - 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

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));
 	}
 
 	/**



Re: svn commit: r886043 - 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

Posted by Sean Qiu <se...@gmail.com>.
Thanks for clarification.

Best Regards
Sean, Xiao Xia Qiu



2009/12/2 Tim Ellison <t....@gmail.com>

> aiting for people to report their results from testing the
> M12 candidate.  Everyone is encouraged to post results, and it is
> expected of the PMC members [1].
>
> Provided we get at least three PMC votes, and no vetoes, by Dec 4 we
> will declare the milestone and re-open the classlib stream.  Sooner if
> all PMCers vote before then.
>

Re: svn commit: r886043 - 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

Posted by Tim Ellison <t....@gmail.com>.
On 02/Dec/2009 09:11, Sean Qiu wrote:
> Sorry, I thought it already opened for commit.
> Revert it back now.

We are still waiting for people to report their results from testing the
M12 candidate.  Everyone is encouraged to post results, and it is
expected of the PMC members [1].

Provided we get at least three PMC votes, and no vetoes, by Dec 4 we
will declare the milestone and re-open the classlib stream.  Sooner if
all PMCers vote before then.

[1] http://people.apache.org/~jim/projects.html#harmony-pmc

Regards,
Tim


Re: svn commit: r886043 - 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

Posted by Sean Qiu <se...@gmail.com>.
Sorry, I thought it already opened for commit.
Revert it back now.

Best Regards
Sean, Xiao Xia Qiu



2009/12/2 Tim Ellison <t....@gmail.com>

> 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, qiuxx@apache.org 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));
> >       }
> >
> >       /**
> >
> >
> >
>

Re: svn commit: r886043 - 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

Posted by Tim Ellison <t....@gmail.com>.
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, qiuxx@apache.org 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));
>  	}
>  
>  	/**
> 
> 
>