From 78516edbe11b879f20d8d9bb64e233cb80044199 Mon Sep 17 00:00:00 2001 From: Daniel Couto Vale Date: Fri, 23 Jan 2015 18:06:11 +0100 Subject: [PATCH] Remove warnings (unclosed readers/writers and unsafe varargs) --- src/opennlp/ccg/grammar/RuleGroup.java | 1 + src/opennlp/ccg/ngrams/SRILM_FactoredScorerMaker.java | 1 + src/opennlp/ccg/parse/Chart.java | 2 ++ src/opennlp/ccg/parse/postagger/ml/POSPriorModel.java | 1 + src/opennlp/ccg/parse/supertagger/ml/STPriorModel.java | 1 + src/opennlp/ccg/util/CompositeFilter.java | 1 + src/opennlp/ccgbank/convert/ApposTally.java | 1 + src/opennlp/ccgbank/convert/InfoHelper.java | 8 +++++--- src/opennlp/ccgbank/convert/MorphLookup.java | 2 ++ src/opennlp/ccgbank/extract/DebugHelper.java | 2 +- src/opennlp/ccgbank/extract/RulesTally.java | 1 + 11 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/opennlp/ccg/grammar/RuleGroup.java b/src/opennlp/ccg/grammar/RuleGroup.java index 7dd6bd9..324c884 100644 --- a/src/opennlp/ccg/grammar/RuleGroup.java +++ b/src/opennlp/ccg/grammar/RuleGroup.java @@ -337,6 +337,7 @@ public void loadSupercatRuleCombos(URL url) throws IOException { supercatRuleCombos.add(new SupercatRuleCombo(tokens[0], tokens[1], tokens[2])); } } + in.close(); } diff --git a/src/opennlp/ccg/ngrams/SRILM_FactoredScorerMaker.java b/src/opennlp/ccg/ngrams/SRILM_FactoredScorerMaker.java index bf9aa48..2e7dd6d 100755 --- a/src/opennlp/ccg/ngrams/SRILM_FactoredScorerMaker.java +++ b/src/opennlp/ccg/ngrams/SRILM_FactoredScorerMaker.java @@ -75,6 +75,7 @@ protected void writeFoldSpecFile(File tmpDir, int foldNum) throws IOException { } } out.close(); + br.close(); } /** diff --git a/src/opennlp/ccg/parse/Chart.java b/src/opennlp/ccg/parse/Chart.java index 58444c0..39d26df 100644 --- a/src/opennlp/ccg/parse/Chart.java +++ b/src/opennlp/ccg/parse/Chart.java @@ -668,8 +668,10 @@ public void loadChartEntries(File file) throws IOException { _size = _table.length; _numUnpackingEdges = 0; } catch (ClassNotFoundException e) { + in.close(); throw (RuntimeException) new RuntimeException().initCause(e); } + in.close(); } diff --git a/src/opennlp/ccg/parse/postagger/ml/POSPriorModel.java b/src/opennlp/ccg/parse/postagger/ml/POSPriorModel.java index 8aa4e72..1c9abd6 100644 --- a/src/opennlp/ccg/parse/postagger/ml/POSPriorModel.java +++ b/src/opennlp/ccg/parse/postagger/ml/POSPriorModel.java @@ -112,6 +112,7 @@ public POSPriorModel(String flmFile, String vocabFile) throws IOException { for (String posTag : allSupertags) { posVocab[cnt++] = posTag.intern(); } + br.close(); } /** Get the prior probability of this POS/word combo. */ diff --git a/src/opennlp/ccg/parse/supertagger/ml/STPriorModel.java b/src/opennlp/ccg/parse/supertagger/ml/STPriorModel.java index 05beed3..aaf7d07 100644 --- a/src/opennlp/ccg/parse/supertagger/ml/STPriorModel.java +++ b/src/opennlp/ccg/parse/supertagger/ml/STPriorModel.java @@ -125,6 +125,7 @@ public STPriorModel(String flmFile, String vocabFile, STTaggerPOSDictionary posD st = st.trim().split("-")[1]; } } + br.close(); // initialize the arrays to this size. stagVocab = new String[cnt]; diff --git a/src/opennlp/ccg/util/CompositeFilter.java b/src/opennlp/ccg/util/CompositeFilter.java index 9ef5053..9739e29 100644 --- a/src/opennlp/ccg/util/CompositeFilter.java +++ b/src/opennlp/ccg/util/CompositeFilter.java @@ -45,6 +45,7 @@ public CompositeFilter() { * Creates a new composite filter made up of the specified filters. * @see #CompositeFilter(Collection) */ + @SafeVarargs public CompositeFilter(Filter... edgeFilters) { this(Arrays.asList(edgeFilters)); } diff --git a/src/opennlp/ccgbank/convert/ApposTally.java b/src/opennlp/ccgbank/convert/ApposTally.java index 914d4e4..c0b1b80 100755 --- a/src/opennlp/ccgbank/convert/ApposTally.java +++ b/src/opennlp/ccgbank/convert/ApposTally.java @@ -70,6 +70,7 @@ public void openCueFile(String fileName) throws IOException { cueList.add(line); //System.out.println(line); } + br.close(); } //Proc which traps, stores id of each sentence in a global var diff --git a/src/opennlp/ccgbank/convert/InfoHelper.java b/src/opennlp/ccgbank/convert/InfoHelper.java index ccc6a0c..a31e2be 100755 --- a/src/opennlp/ccgbank/convert/InfoHelper.java +++ b/src/opennlp/ccgbank/convert/InfoHelper.java @@ -88,6 +88,7 @@ public static void readBBNAuxfiles(String sect){ bbnSpans.put(sentId,spanList); } + inp.close(); } } catch(IOException e){ @@ -120,7 +121,7 @@ public static void readQuoteAuxfiles(String sect){ quotedText=quotedText.trim(); quoteInfo.put(key,quotedText); } - + inp.close(); } } catch(IOException e){ @@ -164,6 +165,7 @@ else if(label.equals("TPC")){ } } } + inp.close(); } } catch(IOException e){ @@ -191,7 +193,7 @@ public static void readTreeAuxfiles(String sect){ String catId=treeParts[2]; treeInfo.put(key,catId); } - + inp.close(); } } @@ -602,7 +604,7 @@ public void printBBNClasses(){ print_writer.print("\"/>"); print_writer.flush(); } - + print_writer.close(); } catch (Exception e){ System.err.println ("Error writing info to file"); diff --git a/src/opennlp/ccgbank/convert/MorphLookup.java b/src/opennlp/ccgbank/convert/MorphLookup.java index ada2880..2395a17 100755 --- a/src/opennlp/ccgbank/convert/MorphLookup.java +++ b/src/opennlp/ccgbank/convert/MorphLookup.java @@ -49,6 +49,8 @@ public static void init(File wordsFile, File stemsFile) throws IOException { stemMap.put(key, stem); stemMap.put(key2, stem); } + wordsReader.close(); + stemsReader.close(); } /** Returns the stem for the given word and pos, or the empty string if none. */ diff --git a/src/opennlp/ccgbank/extract/DebugHelper.java b/src/opennlp/ccgbank/extract/DebugHelper.java index ddee69d..0d75430 100755 --- a/src/opennlp/ccgbank/extract/DebugHelper.java +++ b/src/opennlp/ccgbank/extract/DebugHelper.java @@ -68,7 +68,7 @@ public void readInfo() { //System.out.println(tagInfo); //System.out.println(tagInfo.size()); init = false; - + inp.close(); } catch (IOException e) { diff --git a/src/opennlp/ccgbank/extract/RulesTally.java b/src/opennlp/ccgbank/extract/RulesTally.java index 2555ba8..bf19e8c 100755 --- a/src/opennlp/ccgbank/extract/RulesTally.java +++ b/src/opennlp/ccgbank/extract/RulesTally.java @@ -191,6 +191,7 @@ public static void printTally(File directory) throws FileNotFoundException{ output.println(""); output.println(""); output.flush(); + output.close(); }