SOLR-7574: fix NPE due to missing body with json content type

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1684458 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2015-06-09 15:48:16 +00:00
parent 2abf02438b
commit 645eb35740
3 changed files with 25 additions and 2 deletions

View File

@ -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
----------------------

View File

@ -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

View File

@ -89,6 +89,16 @@ public class TestJsonRequest extends SolrTestCaseHS {
, "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 SolrTestCaseHS {
, "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"