You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/21 15:39:25 UTC
[commons-exec] branch master updated: Use try-with-resource.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-exec.git
The following commit(s) were added to refs/heads/master by this push:
new af3b0c7 Use try-with-resource.
af3b0c7 is described below
commit af3b0c70ef61af13c23f9f0f0bf4bba497d0bf65
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 21 10:39:21 2020 -0500
Use try-with-resource.
---
.../org/apache/commons/exec/launcher/VmsCommandLauncher.java | 9 +--------
src/test/java/org/apache/commons/exec/DefaultExecutorTest.java | 5 +----
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java b/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
index 019ffaa..8f0d28a 100644
--- a/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
+++ b/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
@@ -81,10 +81,7 @@ public class VmsCommandLauncher extends Java13CommandLauncher {
throws IOException {
final File script = File.createTempFile("EXEC", ".TMP");
script.deleteOnExit();
- PrintWriter out = null;
- try {
- out = new PrintWriter(new FileWriter(script.getAbsolutePath(),true));
-
+ try (PrintWriter out = new PrintWriter(new FileWriter(script.getAbsolutePath(),true))) {
// add the environment as global symbols for the DCL script
if (env != null) {
final Set<Entry<String, String>> entries = env.entrySet();
@@ -137,10 +134,6 @@ public class VmsCommandLauncher extends Java13CommandLauncher {
out.print(arg);
}
out.println();
- } finally {
- if (out != null) {
- out.close();
- }
}
return script;
}
diff --git a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
index 1bb4a27..a098a4b 100644
--- a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
+++ b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
@@ -615,16 +615,13 @@ public class DefaultExecutorTest {
final File outfile = File.createTempFile("EXEC", ".test");
outfile.deleteOnExit();
final CommandLine cl = new CommandLine(testScript);
- final FileOutputStream outAndErr = new FileOutputStream(outfile);
- try {
+ try (FileOutputStream outAndErr = new FileOutputStream(outfile)) {
final PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(outAndErr);
final DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(pumpStreamHandler);
final int exitValue = executor.execute(cl);
assertFalse(exec.isFailure(exitValue));
assertTrue(outfile.exists());
- } finally {
- outAndErr.close();
}
}