Skip to content
Permalink
Browse files
[JENKINS-21229] Possible resource leak in parser
- If an exception occurs before the stream is closed there will be a resource leak since close() won't be called.
- Solved using try-finally pattern.
- Indentation fixed.
  • Loading branch information
mixalturek committed Jan 5, 2014
1 parent 1c05513 commit 22fe90021f243b01905e0b4c5ba6f5e03208ac9b
Showing 1 changed file with 13 additions and 8 deletions.
@@ -58,20 +58,25 @@ public SloccountReport parseFiles(java.io.File[] files) {

for (java.io.File file : files) {
try {
parse(file, report);
} catch (IOException e) {
// Silently ignore, there is still a possibility that other
// files can be parsed successfully
}
parse(file, report);
} catch (IOException e) {
// Silently ignore, there is still a possibility that other
// files can be parsed successfully
}
}

return report;
}

private void parse(java.io.File file, SloccountReportInterface report) throws IOException {
InputStreamReader in = new InputStreamReader(new FileInputStream(file), encoding);
this.parse(in, report);
in.close();
InputStreamReader in = null;

try {
in = new InputStreamReader(new FileInputStream(file), encoding);
this.parse(in, report);
} finally {
in.close();
}
}

private void parse(Reader reader, SloccountReportInterface report) throws IOException {

0 comments on commit 22fe900

Please sign in to comment.