Lucene - Core
  1. Lucene - Core
  2. LUCENE-2119

If you pass Integer.MAX_VALUE as 2nd param to search(Query, int) you hit unexpected NegativeArraySizeException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.3, 3.0.2, 3.1, 4.0-ALPHA
    • Component/s: core/search
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      Note that this is a nonsense value to pass in, since our PQ impl allocates the array up front.

      It's because PQ takes 1+ this value (which wraps to -1), and attempts to allocate that. We should bounds check it, and drop PQ size by one in this case.

      Better, maybe: in IndexSearcher, if that n is ever > maxDoc(), set it to maxDoc().

      This trips users up fairly often because they assume our PQ doesn't statically pre-allocate (a reasonable assumption...).

      1. LUCENE-2119.patch
        3 kB
        Michael McCandless

        Activity

        Hide
        Michael McCandless added a comment -

        Patch attached. In PQ if incoming size is Integer.MAX_VALUE, I don't try to +1 it. And, in IndexSearcher.search, when I create PQ, I now use min(nDocs, maxDoc()). I'll commit shortly.

        Show
        Michael McCandless added a comment - Patch attached. In PQ if incoming size is Integer.MAX_VALUE, I don't try to +1 it. And, in IndexSearcher.search, when I create PQ, I now use min(nDocs, maxDoc()). I'll commit shortly.
        Hide
        Michael McCandless added a comment -

        Thanks Paul!

        Show
        Michael McCandless added a comment - Thanks Paul!
        Hide
        Michael McCandless added a comment -

        backport

        Show
        Michael McCandless added a comment - backport

          People

          • Assignee:
            Michael McCandless
            Reporter:
            Michael McCandless
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development