Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-47876 : closed IO streams in finally block #55

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.83</version>
<version>4.86</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void runScript(String scriptPath, String[] args) {
.append(tempFile.getAbsolutePath())
.toString();
for (int i = 0; i < args.length; i++) {
if (args[i] != null && !args[i].equals("")) execScript += " " + args[i];
if (args[i] != null && !args[i].isEmpty()) execScript += " " + args[i];
else execScript += " ''";
}
ProcessBuilder processBuilder = new ProcessBuilder(execScript);
Expand Down Expand Up @@ -172,26 +172,43 @@ private String createHtmlReport(String markdown) {
return "";
}

private String readFile(Path filePath) {
private String readFile(Path filePath) throws IOException {
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;

try {
InputStream is = java.nio.file.Files.newInputStream(filePath);
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr);
is = java.nio.file.Files.newInputStream(filePath);
isr = new InputStreamReader(is, StandardCharsets.UTF_8);
br = new BufferedReader(isr);
return br.lines().collect(Collectors.joining("\n"));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
is.close();
}
if (isr != null) {
isr.close();
}
if (br != null) {
br.close();
}
}
return "";
}

private void writeToFile(File file, String data) {
private void writeToFile(File file, String data) throws IOException {
FileWriter fw = null;
try {
fw = new FileWriter(file, true);
fw.append(data);
fw.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fw != null) {
fw.close();
}
}
}
}
Loading