Apache Solr open-source search software
LUCENE-6608: Fix potential resource leak in BigramDictionary
Uwe Schindler3d4c18d7482e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex e8def73ec75..e83264858e5 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -176,6 +176,9 @@ Bug fixes* LUCENE-6597: Geo3D's GeoCircle now supports a world-globe diameter.(Karl Wright via David Smiley)+* LUCENE-6608: Fix potential resource leak in BigramDictionary.+ (Rishabh Patel via Uwe Schindler)+Changes in Runtime Behavior* LUCENE-6501: The subreader structure in ParallelCompositeReaderdiff --git a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/BigramDictionary.java b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/BigramDictionary.javaindex 9d67afc6232..1a14dd0e8f2 100644--- a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/BigramDictionary.java+++ b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/BigramDictionary.java@@ -65,7 +65,11 @@ class BigramDictionary extends AbstractDictionary {singleInstance.load();} catch (IOException e) {String dictRoot = AnalyzerProfile.ANALYSIS_DATA_DIR;- singleInstance.load(dictRoot);+ try {+ singleInstance.load(dictRoot);+ } catch (IOException ioe) {+ throw new RuntimeException(ioe);+ }} catch (ClassNotFoundException e) {throw new RuntimeException(e);}@@ -84,23 +88,19 @@ class BigramDictionary extends AbstractDictionary {private void loadFromInputStream(InputStream serialObjectInputStream)throws IOException, ClassNotFoundException {- ObjectInputStream input = new ObjectInputStream(serialObjectInputStream);- bigramHashTable = (long[]) input.readObject();- frequencyTable = (int[]) input.readObject();- // log.info("load bigram dict from serialization.");- input.close();+ try (ObjectInputStream input = new ObjectInputStream(serialObjectInputStream)) {+ bigramHashTable = (long[]) input.readObject();+ frequencyTable = (int[]) input.readObject();+ // log.info("load bigram dict from serialization.");+ }}- private void saveToObj(Path serialObj) {- try {- ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(- serialObj));+ private void saveToObj(Path serialObj) throws IOException {+ try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(+ serialObj))) {output.writeObject(bigramHashTable);output.writeObject(frequencyTable);- output.close();// log.info("serialize bigram dict.");- } catch (Exception e) {- // log.warn(e.getMessage());}}@@ -109,7 +109,7 @@ class BigramDictionary extends AbstractDictionary {loadFromInputStream(input);}- private void load(String dictRoot) {+ private void load(String dictRoot) throws IOException {String bigramDictPath = dictRoot + "/bigramdict.dct";Path serialObj = Paths.get(dictRoot + "/bigramdict.mem");