Pankraz76 commented on code in PR #2326:
URL: https://github.com/apache/maven/pull/2326#discussion_r2086842539


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java:
##########
@@ -38,65 +36,54 @@
 import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxReader;
 import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxWriter;
 
-import static org.apache.maven.impl.ImplUtils.nonNull;
 import static org.apache.maven.impl.StaxLocation.getLocation;
 import static org.apache.maven.impl.StaxLocation.getMessage;
 
 @Named
 @Singleton
 public class DefaultPluginXmlFactory implements PluginXmlFactory {
+
+    private static final PluginDescriptorStaxWriter WRITER = new 
PluginDescriptorStaxWriter();
+    private static final PluginDescriptorStaxReader READER = new 
PluginDescriptorStaxReader();
+
     @Override
     public PluginDescriptor read(@Nonnull XmlReaderRequest request) throws 
XmlReaderException {
-        nonNull(request, "request");
-        Path path = request.getPath();
-        URL url = request.getURL();
-        Reader reader = request.getReader();
-        InputStream inputStream = request.getInputStream();
-        if (path == null && url == null && reader == null && inputStream == 
null) {
-            throw new IllegalArgumentException("path, url, reader or 
inputStream must be non null");
-        }
+        READER.setAddDefaultEntities(request.isAddDefaultEntities());
+        var read = request.assertReadable();
         try {
-            PluginDescriptorStaxReader xml = new PluginDescriptorStaxReader();
-            xml.setAddDefaultEntities(request.isAddDefaultEntities());
-            if (inputStream != null) {
-                return xml.read(inputStream, request.isStrict());
-            } else if (reader != null) {
-                return xml.read(reader, request.isStrict());
-            } else if (path != null) {
-                try (InputStream is = Files.newInputStream(path)) {
-                    return xml.read(is, request.isStrict());
-                }
-            } else {
-                try (InputStream is = url.openStream()) {
-                    return xml.read(is, request.isStrict());
+            if (read.getInputStream() != null) {
+                return READER.read(read.getInputStream(), read.isStrict());
+            } else if (read.getReader() != null) {
+                return READER.read(read.getReader(), read.isStrict());
+            } else if (read.getPath() != null) {
+                try (InputStream is = Files.newInputStream(read.getPath())) {
+                    return READER.read(is, read.isStrict());
                 }
             }
-        } catch (Exception e) {
+            try (var is = read.getURL().openStream()) {

Review Comment:
   ```suggestion
               try (InputStream is = read.getURL().openStream()) {
   ```
   Many languages use `val` and `var` as type it not first priority. less seems 
more to me.
   
   - https://github.com/apache/maven/pull/2236
   - https://github.com/apache/maven/pull/2236/files#r2029871372
   - https://projectlombok.org/features/val
   - https://kotlinlang.org/docs/basic-syntax.html#variables
   - 
https://docs.scala-lang.org/overviews/scala-book/two-types-variables.html#the-difference-between-val-and-var



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to