SOLR-898: Fix null pointer exception for the JSON response writer based formats when nl.json=arrarr with null keys.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@723804 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2008-12-05 18:04:11 +00:00
parent 5db15f719a
commit 78bc41b54e
3 changed files with 24 additions and 3 deletions

View File

@ -149,6 +149,9 @@ Bug Fixes
14. SOLR-892: Fix serialization of booleans for PHPSerializedResponseWriter
(yonik)
15. SOLR-898: Fix null pointer exception for the JSON response writer
based formats when nl.json=arrarr with null keys. (yonik)
Other Changes
----------------------

View File

@ -245,13 +245,15 @@ class JSONWriter extends TextResponseWriter {
writeArrayOpener(1);
incLevel();
writeStr(null,key,true);
if (key==null) {
writeNull(null);
} else {
writeStr(null, key, true);
}
writeArraySeparator();
writeVal(key,val.getVal(i));
decLevel();
writeArrayCloser();
}
decLevel();

View File

@ -63,5 +63,21 @@ public class JSONWriterTest extends AbstractSolrTestCase {
w.write(buf, req, rsp);
assertEquals(buf.toString(), "a:3:{s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;}");
}
public void testJSON() throws IOException {
SolrQueryRequest req = req("wt","json","json.nl","arrarr");
SolrQueryResponse rsp = new SolrQueryResponse();
JSONResponseWriter w = new JSONResponseWriter();
StringWriter buf = new StringWriter();
NamedList nl = new NamedList();
nl.add("data1", "hello");
nl.add(null, 42);
rsp.add("nl", nl);
w.write(buf, req, rsp);
assertEquals(buf.toString(), "{\"nl\":[[\"data1\",\"hello\"],[null,42]]}");
}
}