From 206165298805d9867de7729b351e5e2c20d1e84b Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Fri, 1 May 2020 17:31:53 -0500 Subject: [PATCH] Ensure auto close of HTMLStripCharFilter in HtmlStripProcessor The HtmlStripProcessor did not use a try-with resources block to ensure that the used HTMLStripCharFilter is closed. --- .../elasticsearch/ingest/common/HtmlStripProcessor.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/HtmlStripProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/HtmlStripProcessor.java index aaeb5b3310b..b3bd3882868 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/HtmlStripProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/HtmlStripProcessor.java @@ -41,13 +41,11 @@ public final class HtmlStripProcessor extends AbstractStringProcessor { return value; } - HTMLStripCharFilter filter = new HTMLStripCharFilter(new StringReader(value)); - StringBuilder builder = new StringBuilder(); - int ch; - try { + try (HTMLStripCharFilter filter = new HTMLStripCharFilter(new StringReader(value))) { + int ch; while ((ch = filter.read()) != -1) { - builder.append((char)ch); + builder.append((char) ch); } } catch (IOException e) { throw new ElasticsearchException(e);