Skip to content

Commit 24bf3f7

Browse files
author
Vincent Potucek
committed
try can use automatic resource management - current
1 parent 32d9512 commit 24bf3f7

File tree

2 files changed

+2
-21
lines changed
  • its/core-it-support/core-it-plugins
    • maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit
    • maven-it-plugin-log-file/src/main/java/org/apache/maven/plugin/coreit

2 files changed

+2
-21
lines changed

its/core-it-support/core-it-plugins/maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit/CatchMojo.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,11 @@ public void execute() throws MojoExecutionException {
5858

5959
File outfile = new File(outDir, value);
6060

61-
Writer writer = null;
62-
try {
63-
writer = new FileWriter(outfile);
64-
61+
try (Writer writer = new FileWriter(outfile)) {
6562
writer.write(value);
66-
6763
writer.flush();
6864
} catch (IOException e) {
6965
throw new MojoExecutionException("Cannot write output file: " + outfile, e);
70-
} finally {
71-
if (writer != null) {
72-
try {
73-
writer.close();
74-
} catch (IOException e) {
75-
// ignore
76-
}
77-
}
7866
}
7967
}
8068
}

its/core-it-support/core-it-plugins/maven-it-plugin-log-file/src/main/java/org/apache/maven/plugin/coreit/AbstractLogMojo.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,13 @@ protected void append(Object value) throws MojoExecutionException {
8080
getLog().info("[MAVEN-CORE-IT-LOG] " + value);
8181
try {
8282
file.getParentFile().mkdirs();
83-
OutputStream out = new FileOutputStream(file, true);
84-
try {
83+
try (OutputStream out = new FileOutputStream(file, true)) {
8584
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoding));
8685
if (value != null) {
8786
writer.write(value.toString());
8887
writer.newLine();
8988
writer.flush();
9089
}
91-
} finally {
92-
try {
93-
out.close();
94-
} catch (IOException e) {
95-
// just ignore, we tried our best to clean up
96-
}
9790
}
9891
} catch (IOException e) {
9992
throw new MojoExecutionException("Failed to update log file " + logFile, e);

0 commit comments

Comments
 (0)