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

MultiFieldQueryParser doesnt catch invalid syntax properly (due to user using regexpression syntax unwittingly)

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 4.1
    • Fix Version/s: None
    • Component/s: core/queryparser
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      MultiFieldQueryParser doesnt catch invalid syntax properly (due to user using regexpression syntax unwittingly)

       
      import org.apache.lucene.analysis.standard.StandardAnalyzer;
      import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
      import org.apache.lucene.queryparser.classic.ParseException;
      import org.apache.lucene.queryparser.classic.QueryParser;
      import org.apache.lucene.util.Version;
      import org.junit.Test;
      
      import static org.junit.Assert.assertNotNull;
      import static org.junit.Assert.assertTrue;
      
      /**
       * Lucene tests
       */
      public class LuceneRegExParseTest
      {
      
          @Test
          public void testSearch411LuceneBugReport() throws Exception
          {
              Exception e = null;
              try
              {
                  String[] fields = new String[2];
                  fields[0] = "artist";
                  fields[1] = "recording";
      
                  QueryParser qp = new MultiFieldQueryParser(Version.LUCENE_41, fields, new StandardAnalyzer(Version.LUCENE_41));
                  qp.parse("artist:pandora /reyli  recording:yo/Alguien");
              }
              catch(Exception ex)
              {
                  e=ex;
              }
              assertNotNull(e);
              assertTrue(e instanceof ParseException );
          }
      }
      

      With assertions disabled this test fails as no exception is thrown.
      With assertions enabled we get

      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:213)
      	at org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:171)
      	at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:120)
      	at org.musicbrainz.search.servlet.LuceneRegExParseTest.testSearch411LuceneBugReport(LuceneRegExParseTest.java:30)
      
      but this should throw an exception without assertions enabled. Because no exception is thrown a search then faikls with the following stack trace
      
      java.lang.NullPointerException
      at java.util.TreeMap.getEntry(TreeMap.java:342)
      at java.util.TreeMap.get(TreeMap.java:273)
      at org.apache.lucene.codecs.perfield.PerFieldPostingsFormat$FieldsReader.terms(PerFieldPostingsFormat.java:215)
      at org.apache.lucene.search.TermCollectingRewrite.collectTerms(TermCollectingRewrite.java:58)
      at org.apache.lucene.search.ConstantScoreAutoRewrite.rewrite(ConstantScoreAutoRewrite.java:95)
      at org.apache.lucene.search.MultiTermQuery$ConstantScoreAutoRewrite.rewrite(MultiTermQuery.java:220)
      at org.apache.lucene.search.MultiTermQuery.rewrite(MultiTermQuery.java:286)
      at org.apache.lucene.search.BooleanQuery.rewrite(BooleanQuery.java:429)
      at org.apache.lucene.search.IndexSearcher.rewrite(IndexSearcher.java:616)
      at org.apache.lucene.search.IndexSearcher.createNormalizedWeight(IndexSearcher.java:663)
      at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
      at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ijabz Paul taylor
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: