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. TestNullFieldAfterRegexpRewrite.java
        2 kB
        Alan Woodward
      2. mindex-null-field.patch
        0.6 kB
        Alan Woodward
      3. LUCENE-3831.patch
        9 kB
        Michael McCandless

        Activity

        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.
        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...
        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?
        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 -

        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.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development