You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/11/02 23:59:17 UTC

[20/50] [abbrv] lucene-solr:apiv2: SOLR-9701: NPE in export handler when fl parameter is omitted.

SOLR-9701: NPE in export handler when fl parameter is omitted.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/42eab703
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/42eab703
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/42eab703

Branch: refs/heads/apiv2
Commit: 42eab7035ed0d5ebc7ba87f8c08a7677b87b7bef
Parents: 0f8802b
Author: Erick Erickson <er...@apache.org>
Authored: Sat Oct 29 19:47:21 2016 -0700
Committer: Erick Erickson <er...@apache.org>
Committed: Sat Oct 29 19:47:21 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  5 ++++
 .../solr/response/SortingResponseWriter.java    | 27 ++++++++++----------
 .../response/TestSortingResponseWriter.java     | 16 +++++++++++-
 3 files changed, 33 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/42eab703/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3b3fba7..6c3ffcc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -91,6 +91,11 @@ Optimizations
 * SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
   filters specified by using those filters as acceptDocs. (yonik)
 
+Bug Fixes
+----------------------
+* SOLR-9701: NPE in export handler when "fl" parameter is omitted.
+  (Erick Erickson)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/42eab703/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java b/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java
index d99d3dc..56c4f27 100644
--- a/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java
@@ -85,21 +85,23 @@ public class SortingResponseWriter implements QueryResponseWriter {
 
     SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
     SortSpec sortSpec = info.getResponseBuilder().getSortSpec();
-    Exception exception = null;
 
     if(sortSpec == null) {
-      exception = new IOException(new SyntaxError("No sort criteria was provided."));
+      writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
+      return;
     }
 
     SolrIndexSearcher searcher = req.getSearcher();
     Sort sort = searcher.weightSort(sortSpec.getSort());
 
     if(sort == null) {
-      exception = new IOException(new SyntaxError("No sort criteria was provided."));
+      writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
+      return;
     }
 
     if(sort != null && sort.needsScores()) {
-      exception = new IOException(new SyntaxError("Scoring is not currently supported with xsort."));
+      writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
+      return;
     }
 
     // There is a bailout in SolrIndexSearcher.getDocListNC when there are _no_ docs in the index at all.
@@ -117,7 +119,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
       totalHits = ((Integer)req.getContext().get("totalHits")).intValue();
       sets = (FixedBitSet[]) req.getContext().get("export");
       if (sets == null) {
-        exception = new IOException(new SyntaxError("xport RankQuery is required for xsort: rq={!xport}"));
+        writeException((new IOException(new SyntaxError("xport RankQuery is required for xsort: rq={!xport}"))), writer, true);
+        return;
       }
     }
     SolrParams params = req.getParams();
@@ -126,7 +129,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
     String[] fields = null;
 
     if(fl == null) {
-      exception = new IOException(new SyntaxError("export field list (fl) must be specified."));
+      writeException((new IOException(new SyntaxError("export field list (fl) must be specified."))), writer, true);
+      return;
     } else  {
       fields = fl.split(",");
 
@@ -135,8 +139,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
         fields[i] = fields[i].trim();
 
         if(fields[i].equals("score")) {
-          exception =  new IOException(new SyntaxError("Scoring is not currently supported with xsort."));
-          break;
+          writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
+          return;
         }
       }
     }
@@ -146,12 +150,7 @@ public class SortingResponseWriter implements QueryResponseWriter {
     try {
       fieldWriters = getFieldWriters(fields, req.getSearcher());
     } catch (Exception e) {
-      exception = e;
-    }
-
-
-    if(exception != null) {
-      writeException(exception, writer, true);
+      writeException(e, writer, true);
       return;
     }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/42eab703/solr/core/src/test/org/apache/solr/response/TestSortingResponseWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/response/TestSortingResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestSortingResponseWriter.java
index 2691d98d..4b18133 100644
--- a/solr/core/src/test/org/apache/solr/response/TestSortingResponseWriter.java
+++ b/solr/core/src/test/org/apache/solr/response/TestSortingResponseWriter.java
@@ -170,7 +170,21 @@ public class TestSortingResponseWriter extends SolrTestCaseJ4 {
 
     s =  h.query(req("q", "id:8", "qt", "/export", "fl", "stringdv", "sort", "intdv asc"));
     assertEquals(s, "{\"responseHeader\": {\"status\": 0}, \"response\":{\"numFound\":1, \"docs\":[{\"stringdv\":\"chello \\\"world\\\"\"}]}}");
+  }
 
-
+  @Test
+  public void testExportRequiredParams() throws Exception {
+
+    //Test whether missing required parameters returns expected errors.
+
+    //String s =  h.query(req("q", "id:1", "qt", "/export", "fl", "floatdv,intdv,stringdv,longdv,doubledv", "sort", "intdv asc"));
+    String s;
+    s = h.query(req("qt", "/export"));
+    assertTrue("Should have had a sort error", s.contains("No sort criteria"));
+    s = h.query(req("sort", "intdv asc", "qt", "/export"));
+    assertTrue("Should have had fl error", s.contains("export field list (fl) must be specified"));
+    s = h.query(req("sort", "intdv asc", "qt", "/export", "fl", "stringdv"));
+    // Interesting you don't even need to specify a "q" parameter.
+    
   }
 }