Skip to content

Commit efe3699

Browse files
committed
PR: CODEC-225
Fix minor resource leaks. GitHub PR git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1760691 13f79535-47bb-0310-9956-ffa450edef68
1 parent f0028e1 commit efe3699

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
4545
<release version="1.11" date="2016-MM-DD" description="Feature and fix release.">
4646
<!-- The first attribute below should be the issue id; makes it easier to navigate in the IDE outline -->
4747

48+
<action issue="CODEC-225" dev="jochen" type="fix" due-to="Svetlin Zarev">Fix minor resource leaks</action>
4849
<action issue="CODEC-223" dev="sebb" type="remove">Drop obsolete Ant build</action>
4950
<action issue="CODEC-171" dev="sebb" type="add" due-to="Brett Okken">Add support for CRC32-C</action>
5051
<action issue="CODEC-221" dev="sebb" type="update">HmacUtils.updateHmac calls reset() unnecessarily</action>

src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ public String toString() {
232232
}
233233

234234
final Scanner scanner = new Scanner(rulesIS, CharEncoding.UTF_8);
235-
parseRules(scanner, RESOURCE_FILE, RULES, FOLDINGS);
236-
scanner.close();
235+
try {
236+
parseRules(scanner, RESOURCE_FILE, RULES, FOLDINGS);
237+
} finally {
238+
scanner.close();
239+
}
237240

238241
// sort RULES by pattern length in descending order
239242
for (final Map.Entry<Character, List<Rule>> rule : RULES.entrySet()) {

src/main/java/org/apache/commons/codec/language/bm/Rule.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,22 @@ public boolean isMatch(final CharSequence input) {
219219

220220
final Languages ls = Languages.getInstance(s);
221221
for (final String l : ls.getLanguages()) {
222+
final Scanner scanner = createScanner(s, rt, l);
222223
try {
223-
rs.put(l, parseRules(createScanner(s, rt, l), createResourceName(s, rt, l)));
224+
rs.put(l, parseRules(scanner, createResourceName(s, rt, l)));
224225
} catch (final IllegalStateException e) {
225226
throw new IllegalStateException("Problem processing " + createResourceName(s, rt, l), e);
227+
} finally {
228+
scanner.close();
226229
}
227230
}
228231
if (!rt.equals(RuleType.RULES)) {
229-
rs.put("common", parseRules(createScanner(s, rt, "common"), createResourceName(s, rt, "common")));
232+
final Scanner scanner = createScanner(s, rt, "common");
233+
try {
234+
rs.put("common", parseRules(scanner, createResourceName(s, rt, "common")));
235+
} finally {
236+
scanner.close();
237+
}
230238
}
231239

232240
rts.put(rt, Collections.unmodifiableMap(rs));
@@ -435,7 +443,12 @@ private static Map<String, List<Rule>> parseRules(final Scanner scanner, final S
435443
throw new IllegalArgumentException("Malformed import statement '" + rawLine + "' in " +
436444
location);
437445
}
438-
lines.putAll(parseRules(createScanner(incl), location + "->" + incl));
446+
final Scanner hashIncludeScanner = createScanner(incl);
447+
try {
448+
lines.putAll(parseRules(hashIncludeScanner, location + "->" + incl));
449+
} finally {
450+
hashIncludeScanner.close();
451+
}
439452
} else {
440453
// rule
441454
final String[] parts = line.split("\\s+");

0 commit comments

Comments
 (0)