Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-4878

Regular expression syntax with MultiFieldQueryParser causes assert/NPE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1, 4.2
    • Fix Version/s: 4.2.1, 6.0
    • Component/s: core/queryparser
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      Using regex syntax causes MultiFieldQueryParser.parse() to throw an AssertionError (if asserts are on) or causes subsequent searches using the returned Query instance to throw NullPointerException (if asserts are off). Simon Willnauer's comment on the java-user alias: "This is in-fact a bug in the MultiFieldQueryParser [...] MultifieldQueryParser should override getRegexpQuery but it doesn't"

      1. LUCENE-4878.patch
        3 kB
        Simon Willnauer

        Activity

        Hide
        adam@labkey.com Adam Rauch added a comment -

        A simple example that reproduces the assertion:

        // Turn on asserts
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        loader.setDefaultAssertionStatus(true);

        try
        {
        Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_41);
        QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_41, new String[]

        {"title", "body"}

        , analyzer);
        Query query = parser.parse("/study/");
        }
        catch (ParseException e)

        { System.out.println("Syntax error, please rephrase your query"); }

        This produces:

        Exception in thread "main" java.lang.AssertionError
        at org.apache.lucene.search.MultiTermQuery.<init>(MultiTermQuery.java:252)
        at org.apache.lucene.search.AutomatonQuery.<init>(AutomatonQuery.java:65)
        at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:90)
        at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:79)
        at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:69)
        at org.apache.lucene.queryparser.classic.QueryParserBase.newRegexpQuery(QueryParserBase.java:790)
        at org.apache.lucene.queryparser.classic.QueryParserBase.getRegexpQuery(QueryParserBase.java:1005)
        at org.apache.lucene.queryparser.classic.QueryParserBase.handleBareTokenQuery(QueryParserBase.java:1075)
        at org.apache.lucene.queryparser.classic.QueryParser.Term(QueryParser.java:359)
        at org.apache.lucene.queryparser.classic.QueryParser.Clause(QueryParser.java:258)
        at org.apache.lucene.queryparser.classic.QueryParser.Query(QueryParser.java:182)
        at org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:171)
        at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:120)
        at QueryParserException.main(QueryParserException.java:21)

        Show
        adam@labkey.com Adam Rauch added a comment - A simple example that reproduces the assertion: // Turn on asserts ClassLoader loader = ClassLoader.getSystemClassLoader(); loader.setDefaultAssertionStatus(true); try { Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_41); QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_41, new String[] {"title", "body"} , analyzer); Query query = parser.parse("/study/"); } catch (ParseException e) { System.out.println("Syntax error, please rephrase your query"); } This produces: Exception in thread "main" java.lang.AssertionError at org.apache.lucene.search.MultiTermQuery.<init>(MultiTermQuery.java:252) at org.apache.lucene.search.AutomatonQuery.<init>(AutomatonQuery.java:65) at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:90) at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:79) at org.apache.lucene.search.RegexpQuery.<init>(RegexpQuery.java:69) at org.apache.lucene.queryparser.classic.QueryParserBase.newRegexpQuery(QueryParserBase.java:790) at org.apache.lucene.queryparser.classic.QueryParserBase.getRegexpQuery(QueryParserBase.java:1005) at org.apache.lucene.queryparser.classic.QueryParserBase.handleBareTokenQuery(QueryParserBase.java:1075) at org.apache.lucene.queryparser.classic.QueryParser.Term(QueryParser.java:359) at org.apache.lucene.queryparser.classic.QueryParser.Clause(QueryParser.java:258) at org.apache.lucene.queryparser.classic.QueryParser.Query(QueryParser.java:182) at org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:171) at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:120) at QueryParserException.main(QueryParserException.java:21)
        Hide
        simonw Simon Willnauer added a comment -

        thanks for raising this.. I will upload a patch shortly

        Show
        simonw Simon Willnauer added a comment - thanks for raising this.. I will upload a patch shortly
        Hide
        simonw Simon Willnauer added a comment -

        here is a simple patch

        Show
        simonw Simon Willnauer added a comment - here is a simple patch
        Hide
        rcmuir Robert Muir added a comment -

        While we are here can we change this in MultiTermQuery:

        assert field != null;
        

        to this

        if (field == null) {
          throw new NullPointerException();
        }
        
        Show
        rcmuir Robert Muir added a comment - While we are here can we change this in MultiTermQuery: assert field != null ; to this if (field == null ) { throw new NullPointerException(); }
        Hide
        simonw Simon Willnauer added a comment -

        committed to trunk, 4.x branch and 4.2.1 bugfix branch. This should be in the next bugfix release coming pretty soon. Thanks again for reporting

        Show
        simonw Simon Willnauer added a comment - committed to trunk, 4.x branch and 4.2.1 bugfix branch. This should be in the next bugfix release coming pretty soon. Thanks again for reporting
        Hide
        simonw Simon Willnauer added a comment -

        robert, I agree I just committed a IAE to trunk, branch_4x and 4.2.1

        Show
        simonw Simon Willnauer added a comment - robert, I agree I just committed a IAE to trunk, branch_4x and 4.2.1

          People

          • Assignee:
            simonw Simon Willnauer
            Reporter:
            adam@labkey.com Adam Rauch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development