[
https://issues.apache.org/jira/browse/LUCENE-6347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14356998#comment-14356998
]
Paul taylor edited comment on LUCENE-6347 at 3/11/15 3:14 PM:
--------------------------------------------------------------
It only shows the NPE when you run the query, that was the initial problem (and
I think covered by https://issues.apache.org/jira/browse/LUCENE-6345 ) . But
the issue raised here shows that it is failing to throw a ParseException for an
invalid query in the first place when it should, and that is what this issue is
about. To me they are two different (albeit connected issues) that can be fixed
independently.
was (Author: ijabz):
It only shows the NPE when you run the query, that was the initial problem (and
I think covered by https://issues.apache.org/jira/browse/LUCENE-6345 ) . But
the issue raised here shows that it is failing to throw a ParseException for an
invalid query in the first place when it should, and that is what this issue is
about. TO be they are two different (albeit connected issues) that can be fixed
independently.
> MultiFieldQueryParser doesnt catch invalid syntax properly (due to user using
> regexpression syntax unwittingly)
> ---------------------------------------------------------------------------------------------------------------
>
> Key: LUCENE-6347
> URL: https://issues.apache.org/jira/browse/LUCENE-6347
> Project: Lucene - Core
> Issue Type: Bug
> Components: core/queryparser
> Affects Versions: 4.1
> Reporter: Paul taylor
>
> MultiFieldQueryParser doesnt catch invalid syntax properly (due to user using
> regexpression syntax unwittingly)
> {code}
> 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 );
> }
> }
> {code}
> With assertions disabled this test fails as no exception is thrown.
> With assertions enabled we get
> {code}
> 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)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]