another try-with-resources

This commit is contained in:
mikemccand 2015-09-30 17:46:22 +02:00
parent dc01450d95
commit a321300e9c
1 changed files with 10 additions and 21 deletions

View File

@ -619,31 +619,20 @@ public class MapperQueryParser extends QueryParser {
char c = termStr.charAt(i); char c = termStr.charAt(i);
if (c == '?' || c == '*') { if (c == '?' || c == '*') {
if (isWithinToken) { if (isWithinToken) {
try { try (TokenStream source = getAnalyzer().tokenStream(field, tmp.toString())) {
TokenStream source = getAnalyzer().tokenStream(field, tmp.toString()); source.reset();
boolean success = false; CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class);
try { if (source.incrementToken()) {
source.reset(); String term = termAtt.toString();
CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); if (term.length() == 0) {
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 {
// no tokens, just use what we have now // no tokens, just use what we have now
aggStr.append(tmp); aggStr.append(tmp);
}
success = true;
} finally {
if (success) {
source.close();
} else { } else {
IOUtils.close(source); aggStr.append(term);
} }
} else {
// no tokens, just use what we have now
aggStr.append(tmp);
} }
} catch (IOException e) { } catch (IOException e) {
aggStr.append(tmp); aggStr.append(tmp);