Skip to content

Apache Lucene open-source search software

SOLR-5438: DebugComponent throws NPE when used with grouping

Shalin Shekhar Mangar005141020b10
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5d6fdfb83a1..a3066eebabc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -75,6 +75,12 @@ New Features
* SOLR-5308: A new 'migrate' collection API to split all documents with a
route key into another collection (shalin)
+Bug Fixes
+----------------------
+
+* SOLR-5438: DebugComponent throws NPE when used with grouping.
+ (Tomás Fernández Löbbe via shalin)
+
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
index 238d6740dd8..5a35a0356ee 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
@@ -19,26 +19,20 @@ package org.apache.solr.handler.component;
import static org.apache.solr.common.params.CommonParams.FQ;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.CommonParams;
+
import java.io.IOException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
+import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.search.Query;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.DocList;
import org.apache.solr.search.QueryParsing;
import org.apache.solr.util.SolrPluginUtils;
@@ -87,8 +81,14 @@ public class DebugComponent extends SearchComponent
public void process(ResponseBuilder rb) throws IOException
{
if( rb.isDebug() ) {
+ DocList results = null;
+ //some internal grouping requests won't have results value set
+ if(rb.getResults() != null) {
+ results = rb.getResults().docList;
+ }
+
NamedList stdinfo = SolrPluginUtils.doStandardDebug( rb.req,
- rb.getQueryString(), rb.getQuery(), rb.getResults().docList, rb.isDebugQuery(), rb.isDebugResults());
+ rb.getQueryString(), rb.getQuery(), results, rb.isDebugQuery(), rb.isDebugResults());
NamedList info = rb.getDebugInfo();
if( info == null ) {
diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
index ee2bb2495fd..8e9e405f404 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
@@ -326,10 +326,13 @@ public class SolrPluginUtils {
IndexSchema schema = searcher.getSchema();
boolean explainStruct = req.getParams().getBool(CommonParams.EXPLAIN_STRUCT, false);
- NamedList<Explanation> explain = getExplanations(query, results, searcher, schema);
- dbg.add("explain", explainStruct
- ? explanationsToNamedLists(explain)
- : explanationsToStrings(explain));
+ if (results != null) {
+ NamedList<Explanation> explain = getExplanations(query, results, searcher, schema);
+ dbg.add("explain", explainStruct
+ ? explanationsToNamedLists(explain)
+ : explanationsToStrings(explain));
+ }
+
String otherQueryS = req.getParams().get(CommonParams.EXPLAIN_OTHER);
if (otherQueryS != null && otherQueryS.length() > 0) {
DocList otherResults = doSimpleQuery(otherQueryS, req, 0, 10);
diff --git a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
index 68331b50f2d..3eccde1760f 100644
--- a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
+++ b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
@@ -261,6 +261,9 @@ public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
// Can't validate the response, but can check if no errors occur.
simpleQuery("q", "*:*", "rows", 100, "fl", "id," + i1, "group", "true", "group.query", t1 + ":kings OR " + t1 + ":eggs", "group.limit", 10, "sort", i1 + " asc, id asc", CommonParams.TIME_ALLOWED, 1);
+
+ //Debug
+ simpleQuery("q", "*:*", "rows", 10, "fl", "id," + i1, "group", "true", "group.field", i1, "debug", "true");
}
private void simpleQuery(Object... queryParams) throws SolrServerException {
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java
index d0ba84beeeb..521cd05707c 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java
@@ -40,9 +40,9 @@ public class DebugComponentTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
- assertU(adoc("id", "1", "title", "this is a title."));
- assertU(adoc("id", "2", "title", "this is another title."));
- assertU(adoc("id", "3", "title", "Mary had a little lamb."));
+ assertU(adoc("id", "1", "title", "this is a title.", "inStock_b1", "true"));
+ assertU(adoc("id", "2", "title", "this is another title.", "inStock_b1", "true"));
+ assertU(adoc("id", "3", "title", "Mary had a little lamb.", "inStock_b1", "false"));
assertU(commit());
}
@@ -147,7 +147,15 @@ public class DebugComponentTest extends SolrTestCaseJ4 {
"count(//lst[@name='timing']/*)=0"
);
-
+
+ //Grouping
+ assertQ(req("q", "*:*", "debug", CommonParams.RESULTS,
+ "group", CommonParams.TRUE,
+ "group.field", "inStock_b1",
+ "debug", CommonParams.TRUE),
+ "//str[@name='rawquerystring']='*:*'",
+ "count(//lst[@name='explain']/*)=2"
+ );
}
@Test