Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8167658

The result sorted by Arrays.parallelSort(double[]) is different from the result sorted by Arrays.sort(double[])

XMLWordPrintable

      FULL PRODUCT VERSION :
      1.8.0_101-b13

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7

      A DESCRIPTION OF THE PROBLEM :
      The result sorted by Arrays.parallelSort(double[]) is different from the result sorted by Arrays.sort(double[]).
      It can be repeatedly reproduced on my laptop: OS: windows 7 64 bit, CPU: Intel i7-3520M, memory: 16G, 1.8.0_101-b13
      Please refer to the unit test in "steps to reproduce"

      REGRESSION. Last worked in version 8u101

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Here is unit test to verify the bug:

          @Test
          public void test_parallelSort_double() throws Exception {
              assertTrue(Double.compare(Double.NaN, Double.NaN) == 0);

              final Random rand = new Random();
              final int maxSize = 10000;

              for (int i = 0; i < 13; i++) {
                  double[] a = new double[rand.nextInt(maxSize)];

                  for (int j = 0, len = a.length; j < len; j++) {
                      a[j] = j % 3 == 0 ? Double.NaN : rand.nextFloat();
                  }

                  double[] b = a.clone();
                  double[] c = a.clone();
                  Arrays.sort(b);
                  Arrays.parallelSort(c);

                  for (int k = 0, len = a.length; k < len; k++) {
                      if (Double.compare(b[k], c[k]) != 0) {
                          System.out.println(k + ": " + b[k] + ": " + c[k]);
                          // System.out.println(Arrays.toString(b));
                          // System.out.println(Arrays.toString(c));

                          throw new RuntimeException("Test failed");
                      }
                  }
              }
          }


      REPRODUCIBILITY :
      This bug can be reproduced always.

            chegar Chris Hegarty
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: