From 4dd785e5efa7c45aeead2469a8a537e4c075e8f9 Mon Sep 17 00:00:00 2001 From: Joel Bernstein Date: Mon, 3 Apr 2017 20:39:37 -0400 Subject: [PATCH] SOLR-10351: Add try-with-resources clause around TokenStream --- .../apache/solr/handler/AnalyzeEvaluator.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java b/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java index 207f4046590..485f9c39906 100644 --- a/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java +++ b/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java @@ -81,17 +81,16 @@ public class AnalyzeEvaluator extends SimpleEvaluator { return null; } - TokenStream tokenStream = analyzer.tokenStream(analyzerField, value); - CharTermAttribute termAtt = tokenStream.getAttribute(CharTermAttribute.class); - tokenStream.reset(); List tokens = new ArrayList(); - while (tokenStream.incrementToken()) { - tokens.add(termAtt.toString()); + + try(TokenStream tokenStream = analyzer.tokenStream(analyzerField, value)) { + CharTermAttribute termAtt = tokenStream.getAttribute(CharTermAttribute.class); + tokenStream.reset(); + while (tokenStream.incrementToken()) { + tokens.add(termAtt.toString()); + } + tokenStream.end(); } - - tokenStream.end(); - tokenStream.close(); - return tokens; }