From 407080af5bc68c9eb11c05c587368a783ff78d0c Mon Sep 17 00:00:00 2001 From: jbernste Date: Tue, 28 Jun 2016 13:03:34 -0400 Subject: [PATCH] SOLR-9254: GraphTermsQueryQParserPlugin throws NPE when field being search is not present in segment --- solr/CHANGES.txt | 4 ++++ .../java/org/apache/solr/search/GraphTermsQParserPlugin.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ee8babec92f..7fc6f560309 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -86,6 +86,10 @@ Bug Fixes * SOLR-8626: 404 error when clicking nodes in cloud graph view in angular UI. (janhoy, Trey Grainger via shalin) +* SOLR-9254: GraphTermsQueryQParserPlugin throws NPE when field being search is not present in segment + (Joel Bernstein) + + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java index 664fa07d6e9..dfe411a9568 100644 --- a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java @@ -40,9 +40,11 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; import org.apache.lucene.util.ArrayUtil; +import org.apache.lucene.util.BitDocIdSet; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.DocIdSetBuilder; +import org.apache.lucene.util.FixedBitSet; import org.apache.solr.common.params.SolrParams; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.schema.FieldType; @@ -220,6 +222,9 @@ public class GraphTermsQParserPlugin extends QParserPlugin { final LeafReader reader = context.reader(); final Fields fields = reader.fields(); Terms terms = fields.terms(field); + if(terms == null) { + return new WeightOrDocIdSet(new BitDocIdSet(new FixedBitSet(reader.maxDoc()), 0)); + } TermsEnum termsEnum = terms.iterator(); PostingsEnum docs = null; DocIdSetBuilder builder = new DocIdSetBuilder(reader.maxDoc(), terms);