From f48448e93910fbb308d150d2362a487b4e37cf11 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 6 Jul 2023 10:24:20 -0400 Subject: [PATCH] [MJAVADOC-755] replace IOUtil.close with try with resources --- .../org/apache/maven/plugins/javadoc/JavadocUtil.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java index 3333e108c..91942bb31 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -98,7 +98,6 @@ import org.codehaus.plexus.languages.java.version.JavaVersion; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; @@ -983,7 +982,7 @@ private static InvocationResult invoke( InvocationOutputHandler outputHandler = new PrintStreamHandler(ps, false); request.setOutputHandler(outputHandler); - try { + try (OutputStream closeMe = os) { outputHandler.consumeLine("Invoking Maven for the goals: " + goals + " with " + (properties == null ? "no properties" : "properties=" + properties)); outputHandler.consumeLine(""); @@ -992,15 +991,10 @@ private static InvocationResult invoke( outputHandler.consumeLine("JAVA_HOME=" + getJavaHome(log)); outputHandler.consumeLine("JAVA_OPTS=" + getJavaOpts(log)); outputHandler.consumeLine(""); + return invoker.execute(request); } catch (IOException ioe) { throw new MavenInvocationException("IOException while consuming invocation output", ioe); } - - try { - return invoker.execute(request); - } finally { - IOUtil.close(os); - } } /**