Index: lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java (revision 1506631) +++ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java (revision ) @@ -131,9 +131,10 @@ 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 @@ 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 Index: lucene/CHANGES.txt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lucene/CHANGES.txt (revision 1506632) +++ lucene/CHANGES.txt (revision ) @@ -75,6 +75,9 @@ * 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. Index: lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java (revision 1506631) +++ lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java (revision ) @@ -186,6 +186,13 @@ } 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 indexedShapes = new LinkedHashMap(); Index: lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java (revision 1506631) +++ lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java (revision ) @@ -58,6 +58,8 @@ directory = newDirectory(); indexWriter = new RandomIndexWriter(random(),directory); + indexReader = indexWriter.getReader(); + indexSearcher = newSearcher(indexReader); } @Override