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);