Skip to content

Commit

Permalink
[JENKINS-39674] - Prevent file descriptor leak in the Build Name Upda…
Browse files Browse the repository at this point in the history
…ter step
  • Loading branch information
oleg-nenashev committed Mar 2, 2018
1 parent 2074bde commit a2f7021
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.2</version>
<version>3.5</version>
</parent>

<artifactId>build-name-setter</artifactId>
Expand All @@ -13,8 +13,6 @@
<properties>
<jenkins.version>1.625.3</jenkins.version>
<java.level>7</java.level>
<!-- TODO: remove once FindBugs issues are fixed -->
<findbugs.failOnError>false</findbugs.failOnError>
</properties>


Expand Down
Expand Up @@ -8,6 +8,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.EnvironmentVarSetter;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
Expand Down Expand Up @@ -166,11 +168,13 @@ private static class MyFileCallable extends MasterToSlaveFileCallable<String> {
private static final long serialVersionUID = 1L;

@Override
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "Rely on the default system encoding - legacy behavior")
public String invoke(File file, VirtualChannel channel) throws IOException, InterruptedException {
if (file.getAbsoluteFile().exists()){
LOGGER.log(Level.INFO, "File is found, reading...");
BufferedReader br = new BufferedReader(new FileReader(file.getAbsoluteFile()));
return br.readLine();
try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsoluteFile()))) {
return br.readLine();
}
} else {
LOGGER.log(Level.WARNING, "File was not found.");
return "";
Expand Down

0 comments on commit a2f7021

Please sign in to comment.