You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2023/02/26 21:53:45 UTC

[maven] 01/01: Simplify code with try with resources

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

elharo pushed a commit to branch close
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 740991adb91219b689e485778346ff6698d3405f
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sun Feb 26 16:53:31 2023 -0500

    Simplify code with try with resources
---
 .../java/org/apache/maven/internal/xml/XmlNodeBuilder.java | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
index c2b3217a2..92b0918ab 100644
--- a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
+++ b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.maven.api.xml.XmlNode;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -61,17 +60,12 @@ public class XmlNodeBuilder {
 
     public static XmlNodeImpl build(InputStream is, String encoding, boolean trim)
             throws XmlPullParserException, IOException {
-        try {
+        try (InputStream closeMe = is) {
             final XmlPullParser parser = new MXParser();
             parser.setInput(is, encoding);
 
             final XmlNodeImpl node = build(parser, trim);
-            is.close();
-            is = null;
-
             return node;
-        } finally {
-            IOUtil.close(is);
         }
     }
 
@@ -90,17 +84,13 @@ public class XmlNodeBuilder {
      */
     public static XmlNodeImpl build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
             throws XmlPullParserException, IOException {
-        try {
+        try (Reader closeMe = reader) {
             final XmlPullParser parser = new MXParser();
             parser.setInput(reader);
 
             final XmlNodeImpl node = build(parser, trim, locationBuilder);
-            reader.close();
-            reader = null;
 
             return node;
-        } finally {
-            IOUtil.close(reader);
         }
     }