Close XContentParser when executing searches from Watcher (elastic/elasticsearch#4696)

Also removes unused method convertToObject from XContentUtils that does not close XContentParser either.

Original commit: elastic/x-pack-elasticsearch@99ce977c55
This commit is contained in:
Yannick Welsch 2017-01-20 12:40:48 +01:00 committed by GitHub
parent 84936d57ad
commit 8f70653233
2 changed files with 4 additions and 13 deletions

View File

@ -37,16 +37,6 @@ public class XContentUtils {
}
}
public static Tuple<XContentType, Object> convertToObject(BytesReference bytes) throws ElasticsearchParseException {
try {
// EMPTY is safe here because we never call namedObject
XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes);
return Tuple.tuple(parser.contentType(), readValue(parser, parser.nextToken()));
} catch (IOException e) {
throw new ElasticsearchParseException("Failed to parse content to map", e);
}
}
public static String[] readStringArray(XContentParser parser, boolean allowNull) throws IOException {
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
if (allowNull) {

View File

@ -81,9 +81,10 @@ public class ExecutableSearchInput extends ExecutableInput<SearchInput, SearchIn
if (input.getExtractKeys() != null) {
BytesReference bytes = XContentHelper.toXContent(response, XContentType.JSON);
// EMPTY is safe here because we never use namedObject
XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes);
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes)) {
Map<String, Object> filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser);
payload = new Payload.Simple(filteredKeys);
}
} else {
payload = new Payload.XContent(response);
}