Permalink
Browse files

tolerate missing doc

  • Loading branch information...
1 parent 971af70 commit 85da5fc27f22b1cca2451fc994793f943a229171 @hofmeister committed Jun 7, 2011
@@ -586,8 +586,8 @@ public void search(final String query,final HttpServletRequest req,
final List<CouchDocument> fetched_docs = database
.getDocuments(fetch_ids);
for (int j = 0; j < max; j++) {
- rows.getJSONObject(j).put("doc",
- fetched_docs.get(j).asJson());
+ CouchDocument doc = fetched_docs.get(j);
+ rows.getJSONObject(j).put("doc",doc!=null?doc.asJson():null);
}
}
@@ -157,7 +157,7 @@ public UUID getOrCreateUuid() throws IOException, JSONException {
private List<CouchDocument> toDocuments(final JSONObject json) throws JSONException {
final List<CouchDocument> result = new ArrayList<CouchDocument>();
for (final JSONObject doc : rows(json)) {
- result.add(new CouchDocument(doc));
+ result.add(doc != null ? new CouchDocument(doc) : null);
}
return result;
}
@@ -166,7 +166,7 @@ public UUID getOrCreateUuid() throws IOException, JSONException {
final List<JSONObject> result = new ArrayList<JSONObject>();
final JSONArray rows = json.getJSONArray("rows");
for (int i = 0; i < rows.length(); i++) {
- result.add(rows.getJSONObject(i).getJSONObject("doc"));
+ result.add(rows.getJSONObject(i).optJSONObject("doc"));
}
return result;
}

0 comments on commit 85da5fc

Please sign in to comment.