LUCENE-9133 Fix for potential NPE in TermFilteredPresearcher#buildQuery

This commit is contained in:
Marvin Justice 2020-01-13 17:19:44 -05:00 committed by Mike Drob
parent ac866a67de
commit 84f6507452
3 changed files with 10 additions and 1 deletions

View File

@ -154,6 +154,8 @@ Bug Fixes
* LUCENE-8908: Return default value from objectVal when doc doesn't match the query in QueryValueSource
(Bill Bell, hossman, Munendra S N, Michele Palmia)
* LUCENE-9133: Fix for potential NPE in TermFilteredPresearcher for empty fields (Marvin Justice via Mike Drob)
Other
---------------------

View File

@ -105,7 +105,12 @@ public class TermFilteredPresearcher extends Presearcher {
DocumentQueryBuilder queryBuilder = getQueryBuilder();
for (FieldInfo field : reader.getFieldInfos()) {
TokenStream ts = new TermsEnumTokenStream(reader.terms(field.name).iterator());
Terms terms = reader.terms(field.name);
if (terms == null) {
continue;
}
TokenStream ts = new TermsEnumTokenStream(terms.iterator());
for (CustomQueryHandler handler : queryHandlers) {
ts = handler.wrapTermStream(field.name, ts);
}

View File

@ -131,6 +131,7 @@ public class TestTermPresearcher extends PresearcherTestBase {
MemoryIndex mindex = new MemoryIndex();
mindex.addField("f", "this is a test document", WHITESPACE);
mindex.addField("g", "#######", ANALYZER); // analyzes away to empty field
LeafReader docsReader = (LeafReader) mindex.createSearcher().getIndexReader();
QueryIndex.QueryTermFilter termFilter = new QueryIndex.QueryTermFilter(reader);
@ -149,4 +150,5 @@ public class TestTermPresearcher extends PresearcherTestBase {
}
}
}