From a321300e9c1faeb67fa0fe0a906c968352fae873 Mon Sep 17 00:00:00 2001 From: mikemccand Date: Wed, 30 Sep 2015 17:46:22 +0200 Subject: [PATCH] another try-with-resources --- .../classic/MapperQueryParser.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java b/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java index 916d049312c..ca1524f1214 100644 --- a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java +++ b/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java @@ -619,31 +619,20 @@ public class MapperQueryParser extends QueryParser { char c = termStr.charAt(i); if (c == '?' || c == '*') { if (isWithinToken) { - try { - TokenStream source = getAnalyzer().tokenStream(field, tmp.toString()); - boolean success = false; - try { - source.reset(); - CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); - if (source.incrementToken()) { - String term = termAtt.toString(); - if (term.length() == 0) { - // no tokens, just use what we have now - aggStr.append(tmp); - } else { - aggStr.append(term); - } - } else { + try (TokenStream source = getAnalyzer().tokenStream(field, tmp.toString())) { + source.reset(); + CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); + if (source.incrementToken()) { + String term = termAtt.toString(); + if (term.length() == 0) { // no tokens, just use what we have now aggStr.append(tmp); - } - success = true; - } finally { - if (success) { - source.close(); } else { - IOUtils.close(source); + aggStr.append(term); } + } else { + // no tokens, just use what we have now + aggStr.append(tmp); } } catch (IOException e) { aggStr.append(tmp);