You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2015/06/09 17:53:42 UTC
svn commit: r1684460 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/CHANGES.txt solr/core/
solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java
Author: yonik
Date: Tue Jun 9 15:53:41 2015
New Revision: 1684460
URL: http://svn.apache.org/r1684460
Log:
SOLR-7574: fix NPE due to missing body with json content type
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1684460&r1=1684459&r2=1684460&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Tue Jun 9 15:53:41 2015
@@ -115,6 +115,9 @@ Bug Fixes
* SOLR-7518: New Facet Module should respect shards.tolerant and process all non-failing shards
instead of throwing an exception. (yonik)
+* SOLR-7574: A request with a json content type but no body caused a null pointer exception (yonik)
+
+
Other Changes
----------------------
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java?rev=1684460&r1=1684459&r2=1684460&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java Tue Jun 9 15:53:41 2015
@@ -76,7 +76,9 @@ public class RequestUtil {
try {
String jsonString = IOUtils.toString( cs.getReader() );
- MultiMapSolrParams.addParam(JSON, jsonString, map);
+ if (jsonString != null) {
+ MultiMapSolrParams.addParam(JSON, jsonString, map);
+ }
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Exception reading content stream for request:"+req, e);
}
@@ -257,7 +259,10 @@ public class RequestUtil {
path = path.subList(1, path.size());
for (String jsonStr : vals) {
Object o = ObjectBuilder.fromJSON(jsonStr);
- ObjectUtil.mergeObjects(json, path, o, handler);
+ // zero-length strings or comments can cause this to be null (and a zero-length string can result from a json content-type w/o a body)
+ if (o != null) {
+ ObjectUtil.mergeObjects(json, path, o, handler);
+ }
}
} catch (IOException e) {
// impossible
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java?rev=1684460&r1=1684459&r2=1684460&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java Tue Jun 9 15:53:41 2015
@@ -89,6 +89,16 @@ public class TestJsonRequest extends Sol
, "response/numFound==1"
);
+ // test multiple json params with one being zero length
+ client.testJQ( params("json","{query:'cat_s:A'}", "json","{filter:'where_s:NY'}", "json","")
+ , "response/numFound==1"
+ );
+
+ // test multiple json params with one being a comment
+ client.testJQ( params("json","{query:'cat_s:A'}", "json","{filter:'where_s:NY'}", "json","/* */")
+ , "response/numFound==1"
+ );
+
// test merging multi-valued params into list
client.testJQ( params("json","{query:'*:*'}", "json","{filter:'where_s:NY'}", "json","{filter:'cat_s:A'}")
, "response/numFound==1"
@@ -114,6 +124,11 @@ public class TestJsonRequest extends Sol
, "response/numFound==1"
);
+ // test inserting and merging with paths with an empty string and a comment
+ client.testJQ( params("json.query","'*:*'", "json.filter","'where_s:NY'", "json.filter","'cat_s:A'", "json.filter","", "json.filter","/* */")
+ , "response/numFound==1"
+ );
+
// test overwriting of non-multivalued params
client.testJQ( params("json.query","'foo_s:NONE'", "json.filter","'where_s:NY'", "json.filter","'cat_s:A'", "json.query","'*:*'")
, "response/numFound==1"