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

Arrays.binarySearch does not work for arrays larger than 1<<30

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      Various binary search methods in java.util.Arrays compute the average of
      two positive indices (ints) like this:

      int mid = (low + high) >> 1;

      but if low + high overflows into negative territory, the result is negative,
      probably giving undefined results. An easy fix is the simple


      int mid = (low + high) >>> 1;

      although I have not tested whether this is enough to get sort + binary search
      to actually work properly on such gigantic arrays.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                martin Martin Buchholz
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: