Skip to content

Commit

Permalink
Assure stream is closed on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Sep 13, 2023
1 parent 43c38ba commit 65b55c5
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ public static File getObjectsFile(File reference) {
LOGGER.log(

Check warning on line 250 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 250 is not covered by tests
Level.FINEST,
"getObjectsFile(): found an fGit '" + fGit.getAbsolutePath() + "' which is NOT a directory");

Check warning on line 252 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 252 is not covered by tests
BufferedReader reader = null;
try {
try (BufferedReader reader =

Check warning on line 253 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 253 is not covered by tests
new BufferedReader(new InputStreamReader(new FileInputStream(fGit), "UTF-8"))) {
String line;
reader = new BufferedReader(new InputStreamReader(new FileInputStream(fGit), "UTF-8"));
while ((line = reader.readLine()) != null) {

Check warning on line 256 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 256 is only partially covered, 2 branches are missing
String[] parts = line.split(":", 2);

Check warning on line 257 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 257 is not covered by tests
if (parts.length >= 2) {

Check warning on line 258 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 258 is only partially covered, 2 branches are missing
Expand Down Expand Up @@ -295,16 +294,6 @@ public static File getObjectsFile(File reference) {
"getObjectsFile(): failed to parse '" + fGit.getAbsolutePath() + "': " + e.toString());

Check warning on line 294 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 294 is not covered by tests
objects = null;

Check warning on line 295 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 295 is not covered by tests
}

Check warning on line 296 in src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 296 is not covered by tests
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
LOGGER.log(
Level.SEVERE,
"getObjectsFile(): failed to close file after parsing '" + fGit.getAbsolutePath() + "': "
+ e.toString());
}
}
} else {
LOGGER.log(Level.FINEST, "getObjectsFile(): did not find any checked-out '" + fGit.getAbsolutePath() + "'");
Expand Down

0 comments on commit 65b55c5

Please sign in to comment.