Skip to content

Commit

Permalink
close parser when parsing update body
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Oct 6, 2012
1 parent 2fa017d commit 320c9b7
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/main/java/org/elasticsearch/action/update/UpdateRequest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -477,29 +477,33 @@ public UpdateRequest source(byte[] source, int offset, int length) throws Except
public UpdateRequest source(BytesReference source) throws Exception { public UpdateRequest source(BytesReference source) throws Exception {
XContentType xContentType = XContentFactory.xContentType(source); XContentType xContentType = XContentFactory.xContentType(source);
XContentParser parser = XContentFactory.xContent(xContentType).createParser(source); XContentParser parser = XContentFactory.xContent(xContentType).createParser(source);
XContentParser.Token t = parser.nextToken(); try {
if (t == null) { XContentParser.Token t = parser.nextToken();
return this; if (t == null) {
} return this;
String currentFieldName = null; }
while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) { String currentFieldName = null;
if (t == XContentParser.Token.FIELD_NAME) { while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
currentFieldName = parser.currentName(); if (t == XContentParser.Token.FIELD_NAME) {
} else if ("script".equals(currentFieldName)) { currentFieldName = parser.currentName();
script = parser.textOrNull(); } else if ("script".equals(currentFieldName)) {
} else if ("params".equals(currentFieldName)) { script = parser.textOrNull();
scriptParams = parser.map(); } else if ("params".equals(currentFieldName)) {
} else if ("lang".equals(currentFieldName)) { scriptParams = parser.map();
scriptLang = parser.text(); } else if ("lang".equals(currentFieldName)) {
} else if ("upsert".equals(currentFieldName)) { scriptLang = parser.text();
XContentBuilder builder = XContentFactory.contentBuilder(xContentType); } else if ("upsert".equals(currentFieldName)) {
builder.copyCurrentStructure(parser); XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
safeUpsertRequest().source(builder); builder.copyCurrentStructure(parser);
} else if ("doc".equals(currentFieldName)) { safeUpsertRequest().source(builder);
XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType); } else if ("doc".equals(currentFieldName)) {
docBuilder.copyCurrentStructure(parser); XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
safeDoc().source(docBuilder); docBuilder.copyCurrentStructure(parser);
safeDoc().source(docBuilder);
}
} }
} finally {
parser.close();
} }
return this; return this;
} }
Expand Down

0 comments on commit 320c9b7

Please sign in to comment.