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/27 12:38:32 UTC
[maven] branch master updated: Simplify code with try with resources (#1017)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 4e098a320 Simplify code with try with resources (#1017)
4e098a320 is described below
commit 4e098a3205e261ce8bc7fdfe30fa6f46928424d6
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Mon Feb 27 07:38:19 2023 -0500
Simplify code with try with resources (#1017)
---
.../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);
}
}