You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/02/17 20:07:11 UTC

[maven] branch maven-3.9.x updated: Close stream with try-with-resources

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch maven-3.9.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-3.9.x by this push:
     new 0a299275e Close stream with try-with-resources
0a299275e is described below

commit 0a299275e3666cee4bfa6ac6a5942344d3280a4b
Author: Andrey Bruykhov <an...@gmail.com>
AuthorDate: Fri Feb 10 11:08:19 2023 +0300

    Close stream with try-with-resources
    
    This closes #997
---
 .../src/main/java/org/apache/maven/cli/MavenCli.java    | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 61b0e60f6..b2454c4e9 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -41,6 +41,7 @@ import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import com.google.inject.AbstractModule;
 import org.apache.commons.cli.CommandLine;
@@ -334,14 +335,14 @@ public class MavenCli {
             File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
 
             if (configFile.isFile()) {
-                String[] args = Files.lines(configFile.toPath(), Charset.defaultCharset())
-                        .filter(arg -> !arg.isEmpty())
-                        .toArray(size -> new String[size]);
-                mavenConfig = cliManager.parse(args);
-                List<?> unrecognized = mavenConfig.getArgList();
-                if (!unrecognized.isEmpty()) {
-                    // This file can only contain options, not args (goals or phases)
-                    throw new ParseException("Unrecognized maven.config file entries: " + unrecognized);
+                try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
+                    String[] args = lines.filter(arg -> !arg.isEmpty()).toArray(String[]::new);
+                    mavenConfig = cliManager.parse(args);
+                    List<?> unrecognized = mavenConfig.getArgList();
+                    if (!unrecognized.isEmpty()) {
+                        // This file can only contain options, not args (goals or phases)
+                        throw new ParseException("Unrecognized maven.config file entries: " + unrecognized);
+                    }
                 }
             }
         } catch (ParseException e) {