LUCENE-6608: Fix potential resource leak in BigramDictionary

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1687624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-06-25 20:00:44 +00:00
parent 2560638158
commit 3d4c18d748
2 changed files with 17 additions and 14 deletions

View File

@ -176,6 +176,9 @@ Bug fixes
* LUCENE-6597: Geo3D's GeoCircle now supports a world-globe diameter. * LUCENE-6597: Geo3D's GeoCircle now supports a world-globe diameter.
(Karl Wright via David Smiley) (Karl Wright via David Smiley)
* LUCENE-6608: Fix potential resource leak in BigramDictionary.
(Rishabh Patel via Uwe Schindler)
Changes in Runtime Behavior Changes in Runtime Behavior
* LUCENE-6501: The subreader structure in ParallelCompositeReader * LUCENE-6501: The subreader structure in ParallelCompositeReader

View File

@ -65,7 +65,11 @@ class BigramDictionary extends AbstractDictionary {
singleInstance.load(); singleInstance.load();
} catch (IOException e) { } catch (IOException e) {
String dictRoot = AnalyzerProfile.ANALYSIS_DATA_DIR; String dictRoot = AnalyzerProfile.ANALYSIS_DATA_DIR;
singleInstance.load(dictRoot); try {
singleInstance.load(dictRoot);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -84,23 +88,19 @@ class BigramDictionary extends AbstractDictionary {
private void loadFromInputStream(InputStream serialObjectInputStream) private void loadFromInputStream(InputStream serialObjectInputStream)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
ObjectInputStream input = new ObjectInputStream(serialObjectInputStream); try (ObjectInputStream input = new ObjectInputStream(serialObjectInputStream)) {
bigramHashTable = (long[]) input.readObject(); bigramHashTable = (long[]) input.readObject();
frequencyTable = (int[]) input.readObject(); frequencyTable = (int[]) input.readObject();
// log.info("load bigram dict from serialization."); // log.info("load bigram dict from serialization.");
input.close(); }
} }
private void saveToObj(Path serialObj) { private void saveToObj(Path serialObj) throws IOException {
try { try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(
ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream( serialObj))) {
serialObj));
output.writeObject(bigramHashTable); output.writeObject(bigramHashTable);
output.writeObject(frequencyTable); output.writeObject(frequencyTable);
output.close();
// log.info("serialize bigram dict."); // log.info("serialize bigram dict.");
} catch (Exception e) {
// log.warn(e.getMessage());
} }
} }
@ -109,7 +109,7 @@ class BigramDictionary extends AbstractDictionary {
loadFromInputStream(input); loadFromInputStream(input);
} }
private void load(String dictRoot) { private void load(String dictRoot) throws IOException {
String bigramDictPath = dictRoot + "/bigramdict.dct"; String bigramDictPath = dictRoot + "/bigramdict.dct";
Path serialObj = Paths.get(dictRoot + "/bigramdict.mem"); Path serialObj = Paths.get(dictRoot + "/bigramdict.mem");