Harmony
  1. Harmony
  2. HARMONY-866

Arrays.binarySearch should always return -1on empty array

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Environment:
      Windows XP
    • Estimated Complexity:
      Novice

      Description

      Harmony: classlib + VM revision 421248

      If we try to find a non-comparable item in an empty array, RI returns -1 while Harmony throws ClassCastException.

      Code to reproduce:

      import java.util.*;

      public class Test {
      public static void main (String[] args) {
      System.err.println(Arrays.binarySearch(new Object[] {}, new Object()) == -1 ? "PASSED" : "FAILED");
      }
      }
      -------

      Please see the patch with unit test for this case and fix for classlib code attached

      1. patch.txt
        1 kB
        Anton Luht
      2. Harmony-866.diff
        2 kB
        spark shen

        Activity

        Hide
        Paulex Yang added a comment -

        Verified by Anton and Spark.

        Show
        Paulex Yang added a comment - Verified by Anton and Spark.
        Hide
        Anton Luht added a comment -

        verified on build:
        svn = r447316, (Sep 18 2006), Windows/ia32/msvc 1310, debug build

        Show
        Anton Luht added a comment - verified on build: svn = r447316, (Sep 18 2006), Windows/ia32/msvc 1310, debug build
        Hide
        Paulex Yang added a comment -

        Spark, patch applied at revision r447282, thanks a lot for this enhancement.

        Anton, please verify that the problem is fully fixed as you expected.

        Show
        Paulex Yang added a comment - Spark, patch applied at revision r447282, thanks a lot for this enhancement. Anton, please verify that the problem is fully fixed as you expected.
        Hide
        Anton Luht added a comment -

        I've applied this patch successfully to r443308 - it solved the problem.

        Show
        Anton Luht added a comment - I've applied this patch successfully to r443308 - it solved the problem.
        Hide
        spark shen added a comment -

        This is the new patch. Would you please have a try?

        Best regards

        Show
        spark shen added a comment - This is the new patch. Would you please have a try? Best regards
        Hide
        spark shen added a comment -

        I suggest to change the component attribute to classlib, since RI's behavior makes sense here.
        Refer to thread '[OLD JIRA]Deal with 780 866 1367 according to discussion'

        Show
        spark shen added a comment - I suggest to change the component attribute to classlib, since RI's behavior makes sense here. Refer to thread ' [OLD JIRA] Deal with 780 866 1367 according to discussion'
        Hide
        Anton Luht added a comment -

        patch

        Show
        Anton Luht added a comment - patch

          People

          • Assignee:
            Paulex Yang
            Reporter:
            Anton Luht
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development