Permalink
Browse files

close parser when parsing update body

  • Loading branch information...
1 parent 2fa017d commit 320c9b7681ee1ce0cff75e718fcb4a3c3f241298 @kimchy kimchy committed Oct 6, 2012
Showing with 26 additions and 22 deletions.
  1. +26 −22 src/main/java/org/elasticsearch/action/update/UpdateRequest.java
@@ -477,29 +477,33 @@ public UpdateRequest source(byte[] source, int offset, int length) throws Except
public UpdateRequest source(BytesReference source) throws Exception {
XContentType xContentType = XContentFactory.xContentType(source);
XContentParser parser = XContentFactory.xContent(xContentType).createParser(source);
- XContentParser.Token t = parser.nextToken();
- if (t == null) {
- return this;
- }
- String currentFieldName = null;
- while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
- if (t == XContentParser.Token.FIELD_NAME) {
- currentFieldName = parser.currentName();
- } else if ("script".equals(currentFieldName)) {
- script = parser.textOrNull();
- } else if ("params".equals(currentFieldName)) {
- scriptParams = parser.map();
- } else if ("lang".equals(currentFieldName)) {
- scriptLang = parser.text();
- } else if ("upsert".equals(currentFieldName)) {
- XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
- builder.copyCurrentStructure(parser);
- safeUpsertRequest().source(builder);
- } else if ("doc".equals(currentFieldName)) {
- XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
- docBuilder.copyCurrentStructure(parser);
- safeDoc().source(docBuilder);
+ try {
+ XContentParser.Token t = parser.nextToken();
+ if (t == null) {
+ return this;
+ }
+ String currentFieldName = null;
+ while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+ if (t == XContentParser.Token.FIELD_NAME) {
+ currentFieldName = parser.currentName();
+ } else if ("script".equals(currentFieldName)) {
+ script = parser.textOrNull();
+ } else if ("params".equals(currentFieldName)) {
+ scriptParams = parser.map();
+ } else if ("lang".equals(currentFieldName)) {
+ scriptLang = parser.text();
+ } else if ("upsert".equals(currentFieldName)) {
+ XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
+ builder.copyCurrentStructure(parser);
+ safeUpsertRequest().source(builder);
+ } else if ("doc".equals(currentFieldName)) {
+ XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
+ docBuilder.copyCurrentStructure(parser);
+ safeDoc().source(docBuilder);
+ }
}
+ } finally {
+ parser.close();
}
return this;
}

0 comments on commit 320c9b7

Please sign in to comment.