SOLR-10351: Add try-with-resources clause around TokenStream

This commit is contained in:
Joel Bernstein 2017-04-03 20:39:37 -04:00 committed by Shalin Shekhar Mangar
parent 5ee18c8ab5
commit 4dd785e5ef
1 changed files with 8 additions and 9 deletions

View File

@ -81,17 +81,16 @@ public class AnalyzeEvaluator extends SimpleEvaluator {
return null; return null;
} }
TokenStream tokenStream = analyzer.tokenStream(analyzerField, value); List<String> tokens = new ArrayList();
try(TokenStream tokenStream = analyzer.tokenStream(analyzerField, value)) {
CharTermAttribute termAtt = tokenStream.getAttribute(CharTermAttribute.class); CharTermAttribute termAtt = tokenStream.getAttribute(CharTermAttribute.class);
tokenStream.reset(); tokenStream.reset();
List<String> tokens = new ArrayList();
while (tokenStream.incrementToken()) { while (tokenStream.incrementToken()) {
tokens.add(termAtt.toString()); tokens.add(termAtt.toString());
} }
tokenStream.end(); tokenStream.end();
tokenStream.close(); }
return tokens; return tokens;
} }