From bcdec40463005499432ac0ec650efc10ebf648ea Mon Sep 17 00:00:00 2001 From: Pankraz76 <8830888+Pankraz76@users.noreply.github.com> Date: Wed, 11 Jun 2025 08:19:08 +0200 Subject: [PATCH] Revert "`try` can use `automatic resource management` in CatchMojo (#2424)" This reverts commit 555503260045c6be8133fae6505195bcc4230578. --- .../org/apache/maven/plugin/coreit/CatchMojo.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 65a38789155a..b0789f3a54f7 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,10 +58,23 @@ public void execute() throws MojoExecutionException { File outfile = new File(outDir, value); - try (Writer writer = new FileWriter(outfile)) { + Writer writer = null; + try { + 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 + } + } } } }