Skip to content

Commit 320c9b7

Browse files
committed
close parser when parsing update body
1 parent 2fa017d commit 320c9b7

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/main/java/org/elasticsearch/action/update/UpdateRequest.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -477,29 +477,33 @@ public UpdateRequest source(byte[] source, int offset, int length) throws Except
477477
public UpdateRequest source(BytesReference source) throws Exception {
478478
XContentType xContentType = XContentFactory.xContentType(source);
479479
XContentParser parser = XContentFactory.xContent(xContentType).createParser(source);
480-
XContentParser.Token t = parser.nextToken();
481-
if (t == null) {
482-
return this;
483-
}
484-
String currentFieldName = null;
485-
while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
486-
if (t == XContentParser.Token.FIELD_NAME) {
487-
currentFieldName = parser.currentName();
488-
} else if ("script".equals(currentFieldName)) {
489-
script = parser.textOrNull();
490-
} else if ("params".equals(currentFieldName)) {
491-
scriptParams = parser.map();
492-
} else if ("lang".equals(currentFieldName)) {
493-
scriptLang = parser.text();
494-
} else if ("upsert".equals(currentFieldName)) {
495-
XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
496-
builder.copyCurrentStructure(parser);
497-
safeUpsertRequest().source(builder);
498-
} else if ("doc".equals(currentFieldName)) {
499-
XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
500-
docBuilder.copyCurrentStructure(parser);
501-
safeDoc().source(docBuilder);
480+
try {
481+
XContentParser.Token t = parser.nextToken();
482+
if (t == null) {
483+
return this;
484+
}
485+
String currentFieldName = null;
486+
while ((t = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
487+
if (t == XContentParser.Token.FIELD_NAME) {
488+
currentFieldName = parser.currentName();
489+
} else if ("script".equals(currentFieldName)) {
490+
script = parser.textOrNull();
491+
} else if ("params".equals(currentFieldName)) {
492+
scriptParams = parser.map();
493+
} else if ("lang".equals(currentFieldName)) {
494+
scriptLang = parser.text();
495+
} else if ("upsert".equals(currentFieldName)) {
496+
XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
497+
builder.copyCurrentStructure(parser);
498+
safeUpsertRequest().source(builder);
499+
} else if ("doc".equals(currentFieldName)) {
500+
XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
501+
docBuilder.copyCurrentStructure(parser);
502+
safeDoc().source(docBuilder);
503+
}
502504
}
505+
} finally {
506+
parser.close();
503507
}
504508
return this;
505509
}

0 commit comments

Comments
 (0)