LUCENE-5132: Spatial RPT Contains predicate can throw NPE

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1506811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2013-07-25 03:24:06 +00:00
parent e4e4f096c7
commit 62eb152234
4 changed files with 16 additions and 1 deletions

View File

@ -75,6 +75,9 @@ Bug Fixes
* LUCENE-4734: Add FastVectorHighlighter support for proximity queries and
phrase queries with gaps or overlapping terms. (Ryan Lauck, Adrien Grand)
* LUCENE-5132: Spatial RecursivePrefixTree Contains predicate will throw an NPE
when there's no indexed data and maybe in other circumstances too. (David Smiley)
API Changes
* LUCENE-5094: Add ramBytesUsed() to MultiDocValues.OrdinalMap.

View File

@ -131,9 +131,10 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter {
private boolean seekExact(Cell cell) throws IOException {
assert new BytesRef(cell.getTokenBytes()).compareTo(termBytes) > 0;
termBytes.bytes = cell.getTokenBytes();
termBytes.length = termBytes.bytes.length;
if (termsEnum == null)
return false;
return termsEnum.seekExact(termBytes);
}
@ -150,6 +151,8 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter {
assert ! leafCell.equals(lastLeaf);//don't call for same leaf again
lastLeaf = leafCell;
if (termsEnum == null)
return null;
BytesRef nextTerm = termsEnum.next();
if (nextTerm == null) {
termsEnum = null;//signals all done

View File

@ -58,6 +58,8 @@ public abstract class SpatialTestCase extends LuceneTestCase {
directory = newDirectory();
indexWriter = new RandomIndexWriter(random(),directory);
indexReader = indexWriter.getReader();
indexSearcher = newSearcher(indexReader);
}
@Override

View File

@ -186,6 +186,13 @@ public class SpatialOpRecursivePrefixTreeTest extends StrategyTestCase {
}
private void doTest(final SpatialOperation operation) throws IOException {
//first show that when there's no data, a query will result in no results
{
Query query = strategy.makeQuery(new SpatialArgs(operation, randomRectangle()));
SearchResults searchResults = executeQuery(query, 1);
assertEquals(0, searchResults.numFound);
}
final boolean biasContains = (operation == SpatialOperation.Contains);
Map<String, Shape> indexedShapes = new LinkedHashMap<String, Shape>();