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:48:17 UTC
svn commit: r1684458 - in /lucene/dev/trunk/solr: CHANGES.txt
core/src/java/org/apache/solr/request/json/RequestUtil.java
core/src/test/org/apache/solr/search/json/TestJsonRequest.java
Author: yonik
Date: Tue Jun 9 15:48:16 2015
New Revision: 1684458
URL: http://svn.apache.org/r1684458
Log:
SOLR-7574: fix NPE due to missing body with json content type
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1684458&r1=1684457&r2=1684458&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Jun 9 15:48:16 2015
@@ -174,6 +174,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/trunk/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java?rev=1684458&r1=1684457&r2=1684458&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java Tue Jun 9 15:48:16 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/trunk/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java?rev=1684458&r1=1684457&r2=1684458&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java Tue Jun 9 15:48:16 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"