Skip to content

Commit e7f9daf

Browse files
committed
Make sure the scanner is always closed.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1539802 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2abec26 commit e7f9daf

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,24 @@ public static Languages getInstance(final String languagesResourceName) {
158158
}
159159

160160
final Scanner lsScanner = new Scanner(langIS, ResourceConstants.ENCODING);
161-
boolean inExtendedComment = false;
162-
while (lsScanner.hasNextLine()) {
163-
final String line = lsScanner.nextLine().trim();
164-
if (inExtendedComment) {
165-
if (line.endsWith(ResourceConstants.EXT_CMT_END)) {
166-
inExtendedComment = false;
167-
}
168-
} else {
169-
if (line.startsWith(ResourceConstants.EXT_CMT_START)) {
170-
inExtendedComment = true;
171-
} else if (line.length() > 0) {
172-
ls.add(line);
161+
try {
162+
boolean inExtendedComment = false;
163+
while (lsScanner.hasNextLine()) {
164+
final String line = lsScanner.nextLine().trim();
165+
if (inExtendedComment) {
166+
if (line.endsWith(ResourceConstants.EXT_CMT_END)) {
167+
inExtendedComment = false;
168+
}
169+
} else {
170+
if (line.startsWith(ResourceConstants.EXT_CMT_START)) {
171+
inExtendedComment = true;
172+
} else if (line.length() > 0) {
173+
ls.add(line);
174+
}
173175
}
174176
}
177+
} finally {
178+
lsScanner.close();
175179
}
176180

177181
return new Languages(Collections.unmodifiableSet(ls));

0 commit comments

Comments
 (0)