From 8f7065323332c2377feb78d4c0ea44f5d773f1f1 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Fri, 20 Jan 2017 12:40:48 +0100 Subject: [PATCH] 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@99ce977c55a78fb7d18f0ac8f20e3a0408c80ba6 --- .../xpack/common/xcontent/XContentUtils.java | 10 ---------- .../watcher/input/search/ExecutableSearchInput.java | 7 ++++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/common/xcontent/XContentUtils.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/common/xcontent/XContentUtils.java index 25d7ecc01aa..6762b1a3c12 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/common/xcontent/XContentUtils.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/common/xcontent/XContentUtils.java @@ -37,16 +37,6 @@ public class XContentUtils { } } - public static Tuple 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) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java index 4adcfec196a..86721490215 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/ExecutableSearchInput.java @@ -81,9 +81,10 @@ public class ExecutableSearchInput extends ExecutableInput filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser); - payload = new Payload.Simple(filteredKeys); + try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes)) { + Map filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser); + payload = new Payload.Simple(filteredKeys); + } } else { payload = new Payload.XContent(response); }