From e9b74ce08f275c7879f65865c84595c05081f3d7 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Mon, 2 Jun 2025 09:05:47 +0200 Subject: [PATCH] `try` can use `automatic resource management` in CatchMojo --- .../org/apache/maven/plugin/coreit/CatchMojo.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit/CatchMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit/CatchMojo.java index b0789f3a54f7..65a38789155a 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit/CatchMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-context-passing/src/main/java/org/apache/maven/plugin/coreit/CatchMojo.java @@ -58,23 +58,10 @@ public void execute() throws MojoExecutionException { File outfile = new File(outDir, value); - Writer writer = null; - try { - writer = new FileWriter(outfile); - + try (Writer writer = new FileWriter(outfile)) { writer.write(value); - - writer.flush(); } catch (IOException e) { throw new MojoExecutionException("Cannot write output file: " + outfile, e); - } finally { - if (writer != null) { - try { - writer.close(); - } catch (IOException e) { - // ignore - } - } } } }