From 5b51479b69ec3c52e42c9b95418ee285080311f7 Mon Sep 17 00:00:00 2001 From: David Smiley Date: Mon, 2 May 2016 22:39:32 -0400 Subject: [PATCH] LUCENE-7262: Fix NPE, this should lazy-init in start() (cherry picked from commit 91153b9) --- .../spatial/composite/IntersectsRPTVerifyQuery.java | 11 ++++++----- .../spatial/prefix/AbstractPrefixTreeQuery.java | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java index 886491e5454..ebb3ada20f8 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java @@ -19,9 +19,6 @@ package org.apache.lucene.spatial.composite; import java.io.IOException; import java.util.Map; -import org.locationtech.spatial4j.shape.Shape; -import org.locationtech.spatial4j.shape.SpatialRelation; - import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; @@ -38,6 +35,8 @@ import org.apache.lucene.spatial.prefix.AbstractVisitingPrefixTreeQuery; import org.apache.lucene.spatial.prefix.tree.Cell; import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; import org.apache.lucene.util.DocIdSetBuilder; +import org.locationtech.spatial4j.shape.Shape; +import org.locationtech.spatial4j.shape.SpatialRelation; /** * A spatial Intersects predicate that distinguishes an approximated match from an exact match based on which cells @@ -163,8 +162,8 @@ public class IntersectsRPTVerifyQuery extends Query { // TODO consider if IntersectsPrefixTreeQuery should simply do this and provide both sets class IntersectsDifferentiatingVisitor extends VisitorTemplate { - DocIdSetBuilder approxBuilder = new DocIdSetBuilder(maxDoc, terms); - DocIdSetBuilder exactBuilder = new DocIdSetBuilder(maxDoc, terms); + DocIdSetBuilder approxBuilder; + DocIdSetBuilder exactBuilder; boolean approxIsEmpty = true; boolean exactIsEmpty = true; DocIdSet exactDocIdSet; @@ -176,6 +175,8 @@ public class IntersectsRPTVerifyQuery extends Query { @Override protected void start() throws IOException { + approxBuilder = new DocIdSetBuilder(maxDoc, terms); + exactBuilder = new DocIdSetBuilder(maxDoc, terms); } @Override diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java index 11cc22c36a5..e599e79ab0e 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java @@ -18,7 +18,6 @@ package org.apache.lucene.spatial.prefix; import java.io.IOException; -import org.locationtech.spatial4j.shape.Shape; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PostingsEnum; @@ -35,6 +34,7 @@ import org.apache.lucene.search.Weight; import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.DocIdSetBuilder; +import org.locationtech.spatial4j.shape.Shape; /** * Base class for Lucene Queries on SpatialPrefixTree fields. @@ -105,7 +105,7 @@ public abstract class AbstractPrefixTreeQuery extends Query { protected final LeafReaderContext context; protected final int maxDoc; - protected final Terms terms; + protected final Terms terms; // maybe null protected final TermsEnum termsEnum;//remember to check for null! protected PostingsEnum postingsEnum;