You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2016/11/12 17:16:34 UTC

[2/8] lucene-solr:jira/solr-8593: LUCENE-7547: close the dictionary file so we don't leak file handles

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


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/bd6c0523
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/bd6c0523
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/bd6c0523

Branch: refs/heads/jira/solr-8593
Commit: bd6c0523c2de09250ff07db6e4a21227bd143ea2
Parents: 77605fe
Author: Mike McCandless <mi...@apache.org>
Authored: Fri Nov 11 13:42:06 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Fri Nov 11 13:42:06 2016 -0500

----------------------------------------------------------------------
 lucene/CHANGES.txt                                 |  5 +++++
 .../analysis/ja/JapaneseTokenizerFactory.java      | 17 +++++++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bd6c0523/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9cce927..1caaf86 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bd6c0523/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java
index 99ad61b..844684a 100644
--- a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java
+++ b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java
@@ -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;
     }