Lucene - Core
  1. Lucene - Core
  2. LUCENE-3831

Passing a null fieldname to MemoryFields#terms in MemoryIndex throws a NPE

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 4.0-ALPHA
    • Fix Version/s: 3.6, 4.0-ALPHA
    • Component/s: core/index
    • Labels:
      None
    • Lucene Fields:
      New, Patch Available

      Description

      I found this when querying a MemoryIndex using a RegexpQuery wrapped by a SpanMultiTermQueryWrapper. If the regexp doesn't match anything in the index, it gets rewritten to an empty SpanOrQuery with a null field value, which then triggers the NPE.

      1. mindex-null-field.patch
        0.6 kB
        Alan Woodward
      2. TestNullFieldAfterRegexpRewrite.java
        2 kB
        Alan Woodward
      3. LUCENE-3831.patch
        9 kB
        Michael McCandless

        Activity

        Alan Woodward created issue -
        Hide
        Alan Woodward added a comment -

        Trivial fix - we just check if the passed in fieldname is null, and if it is, return null.

        Show
        Alan Woodward added a comment - Trivial fix - we just check if the passed in fieldname is null, and if it is, return null.
        Alan Woodward made changes -
        Field Original Value New Value
        Attachment mindex-null-field.patch [ 12516313 ]
        Michael McCandless made changes -
        Assignee Michael McCandless [ mikemccand ]
        Hide
        Michael McCandless added a comment -

        Hmm I don't think the Fields.terms API should be expected to accept null (eg I don't know if the other codecs will NPE).

        I'd rather fix span queries to not pass the null field. Is this happening in SpanTermQuery.getSpans()?

        Show
        Michael McCandless added a comment - Hmm I don't think the Fields.terms API should be expected to accept null (eg I don't know if the other codecs will NPE). I'd rather fix span queries to not pass the null field. Is this happening in SpanTermQuery.getSpans()?
        Hide
        Alan Woodward added a comment -

        Here's a test case. The error is thrown in SpanQuery.createWeight() when it's called on a bare SpanMultiTermQueryWrapper.

        It looks as though a simple workaround is to always wrap SpanMultiTermQueryWrapper in a SpanOrQuery.

        Maybe SpanOrQuery should not have a default constructor, but should require a fieldname if no clauses are supplied?

        Show
        Alan Woodward added a comment - Here's a test case. The error is thrown in SpanQuery.createWeight() when it's called on a bare SpanMultiTermQueryWrapper. It looks as though a simple workaround is to always wrap SpanMultiTermQueryWrapper in a SpanOrQuery. Maybe SpanOrQuery should not have a default constructor, but should require a fieldname if no clauses are supplied?
        Alan Woodward made changes -
        Attachment TestNullFieldAfterRegexpRewrite.java [ 12516332 ]
        Hide
        Michael McCandless added a comment -

        Thanks for the test cases Alan!

        I folded those into a patch, added a few assert field != null,
        and then fixed SpanWeight to detect when its .getField() is
        null and return a null scorer in that case.

        I'd like to avoid the API break (changing Span*Query API to force
        up-front providing of the field) if we can...

        Show
        Michael McCandless added a comment - Thanks for the test cases Alan! I folded those into a patch, added a few assert field != null , and then fixed SpanWeight to detect when its .getField() is null and return a null scorer in that case. I'd like to avoid the API break (changing Span*Query API to force up-front providing of the field) if we can...
        Michael McCandless made changes -
        Attachment LUCENE-3831.patch [ 12516340 ]
        Hide
        Michael McCandless added a comment -

        Thanks Alan.

        I couldn't provoke an NPE on 3.x but I still fixed SpanWeight to not pass on a null field to IR.norms.

        Show
        Michael McCandless added a comment - Thanks Alan. I couldn't provoke an NPE on 3.x but I still fixed SpanWeight to not pass on a null field to IR.norms.
        Michael McCandless made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.6 [ 12319070 ]
        Fix Version/s 4.0 [ 12314025 ]
        Resolution Fixed [ 1 ]
        Uwe Schindler made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        8d 8h 7m 1 Michael McCandless 07/Mar/12 19:38
        Resolved Resolved Closed Closed
        428d 15h 5m 1 Uwe Schindler 10/May/13 11:43

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development