LUCENE-7547: close the dictionary file so we don't leak file handles

This commit is contained in:
Mike McCandless 2016-11-11 13:42:06 -05:00
parent 77605fe7b7
commit bd6c0523c2
2 changed files with 14 additions and 8 deletions

View File

@ -60,6 +60,11 @@ New features
* LUCENE-5867: Added BooleanSimilarity. (Robert Muir, Adrien Grand)
Bug Fixes
* LUCENE-7547: JapaneseTokenizerFactory was failing to close the
dictionary file it opened (Markus via Mike McCandless)
Improvements
* LUCENE-6824: TermAutomatonQuery now rewrites to TermQuery,

View File

@ -127,16 +127,17 @@ public class JapaneseTokenizerFactory extends TokenizerFactory implements Resour
@Override
public void inform(ResourceLoader loader) throws IOException {
if (userDictionaryPath != null) {
InputStream stream = loader.openResource(userDictionaryPath);
String encoding = userDictionaryEncoding;
if (encoding == null) {
encoding = IOUtils.UTF_8;
}
CharsetDecoder decoder = Charset.forName(encoding).newDecoder()
try (InputStream stream = loader.openResource(userDictionaryPath)) {
String encoding = userDictionaryEncoding;
if (encoding == null) {
encoding = IOUtils.UTF_8;
}
CharsetDecoder decoder = Charset.forName(encoding).newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
Reader reader = new InputStreamReader(stream, decoder);
userDictionary = UserDictionary.open(reader);
Reader reader = new InputStreamReader(stream, decoder);
userDictionary = UserDictionary.open(reader);
}
} else {
userDictionary = null;
}