Skip to content

Commit

Permalink
BackupFileRotationTest: Fix resource leaks on exceptional path
Browse files Browse the repository at this point in the history
Errors reported by Coverity Scan:

CID 50569 (#1 of 1): Resource leak on an exceptional path (RESOURCE_LEAK)
CID 50570 (#1 of 1): Resource leak on an exceptional path (RESOURCE_LEAK)

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Sep 23, 2016
1 parent e7265f8 commit bbb3759
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Goobi/test/src/org/goobi/io/BackupFileRotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ private void runBackup(int numberOfBackups, String format) throws IOException {

private void assertFileHasContent(String fileName, String expectedContent) throws IOException {
File testFile = new File(fileName);
FileReader reader = new FileReader(testFile);
BufferedReader br = new BufferedReader(reader);
String content = br.readLine();
br.close();
reader.close();
assertEquals("File " + fileName + " does not contain expected content:", expectedContent, content);
try (
FileReader reader = new FileReader(testFile);
BufferedReader br = new BufferedReader(reader);
) {
String content = br.readLine();
assertEquals("File " + fileName + " does not contain expected content:", expectedContent, content);
}
}

private void assertFileExists(String fileName) {
Expand Down Expand Up @@ -232,9 +233,9 @@ private void deleteFile(String fileName) {

private void writeFile(String fileName, String content) throws IOException {
File testFile = new File(fileName);
FileWriter writer = new FileWriter(testFile);
writer.write(content);
writer.close();
try (FileWriter writer = new FileWriter(testFile)) {
writer.write(content);
}
}

}

0 comments on commit bbb3759

Please sign in to comment.