From 1ed64a599d4725da9616637c9f7bcfb9b06e5eaf Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Thu, 5 Jun 2025 11:51:43 +0200 Subject: [PATCH] use try-with-resources statement in CheckThreadSafetyMojo --- .../plugin/coreit/CheckThreadSafetyMojo.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java index f8f4441bd7cf..ff39469472b2 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java @@ -133,21 +133,11 @@ public void run() { 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)) { componentProperties.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);