Harmony
  1. Harmony
  2. HARMONY-6395

[classlib][luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0M11
    • Fix Version/s: 5.0M13
    • Component/s: Classlib
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      There is a simple testcase as below. You can see StackOverflowError if run this testcase. This is a defect of Arrays.sort(double []), I have attached a fix for it.

      import java.util.Arrays;

      public class SortTest {
      public static void main(String[] args) {
      double[] array =

      { Double.NaN, 1.0, 2.0, Double.NaN, Double.NaN, 3.0, 4.0 }

      ;
      displayArray(array);
      Arrays.sort(array);
      displayArray(array);

      System.out.println();
      }

      private static void displayArray(double[] array)

      { for (double d : array) System.out.print(d + " "); System.out.println(); }

      }

      1. HARMONY-6395.diff
        3 kB
        Jim Yu
      2. harmony-6395-2.patch
        5 kB
        Tim Ellison

        Activity

        Hide
        Jim Yu added a comment -

        You can reproduce this defect with arrays input whose length is larger than 6 and there are several Double.NaN elements in it.

        Show
        Jim Yu added a comment - You can reproduce this defect with arrays input whose length is larger than 6 and there are several Double.NaN elements in it.
        Hide
        Hudson added a comment -

        Integrated in Harmony-1.5-head-linux-x86_64 #572 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/572/)
        Apply for , [classlib][luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input

        Show
        Hudson added a comment - Integrated in Harmony-1.5-head-linux-x86_64 #572 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/572/ ) Apply for , [classlib] [luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input
        Hide
        Hudson added a comment -

        Integrated in Harmony-1.5-head-linux-x86_64 #573 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/573/)
        Revert r886043 "Apply for , [classlib][luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input"

        Show
        Hudson added a comment - Integrated in Harmony-1.5-head-linux-x86_64 #573 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/573/ ) Revert r886043 "Apply for , [classlib] [luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input"
        Hide
        Tim Ellison added a comment -

        I disagree with the original patch on this issue,
        1) it is very inefficient since it calls Double.doubleToLongBits multiple times, which is an expensive operation,
        2) it doesn't handle +0.0 and -0.0 cases properly, since for sorting +0.0d is considered greater than -0.0d.

        Alternative patch is attached for your comment. If you agree I'll apply it.

        Show
        Tim Ellison added a comment - I disagree with the original patch on this issue, 1) it is very inefficient since it calls Double.doubleToLongBits multiple times, which is an expensive operation, 2) it doesn't handle +0.0 and -0.0 cases properly, since for sorting +0.0d is considered greater than -0.0d. Alternative patch is attached for your comment. If you agree I'll apply it.
        Hide
        Tim Ellison added a comment -

        Oh, and the original patch only fixed the double case, there was the identical code for float that was left unfixed.

        Show
        Tim Ellison added a comment - Oh, and the original patch only fixed the double case, there was the identical code for float that was left unfixed.
        Hide
        Sean Qiu added a comment -

        Jim, what do you think about Tim's patch?
        It is all right for me.

        if you agree, I will apply Tim' s patch instead.

        Show
        Sean Qiu added a comment - Jim, what do you think about Tim's patch? It is all right for me. if you agree, I will apply Tim' s patch instead.
        Hide
        Jim Yu added a comment -

        I'm fine with it. Thanks Tim for figuring it out.

        Show
        Jim Yu added a comment - I'm fine with it. Thanks Tim for figuring it out.
        Hide
        Tim Ellison added a comment -

        Fix applied at repo revision r896060.

        Please verify.

        Show
        Tim Ellison added a comment - Fix applied at repo revision r896060. Please verify.
        Hide
        Hudson added a comment -

        Integrated in Harmony-1.5-head-linux-x86_64 #589 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/589/)
        Apply patch for ([classlib][luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input)

        Show
        Hudson added a comment - Integrated in Harmony-1.5-head-linux-x86_64 #589 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/589/ ) Apply patch for ( [classlib] [luni] Arrays.sort(double []) will result in StackOverflowError for specific arrays input)

          People

          • Assignee:
            Sean Qiu
            Reporter:
            Jim Yu
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development