From 3b321f4bf0597a67d30a3901144b166ca4487ba5 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Wed, 4 Jun 2025 13:39:31 +0200 Subject: [PATCH] use try-with-resources statement in LookupWagonMojo --- .../maven/plugin/coreit/LookupWagonMojo.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java index 278868010a17..93d0bf9527b6 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java @@ -92,21 +92,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("[MAVEN-CORE-IT-LOG] Creating output file " + outputFile); - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { loaderProperties.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException("Output file could not be created: " + outputFile, e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } getLog().info("[MAVEN-CORE-IT-LOG] Created output file " + outputFile);