{"record":{"id":"c2d63e864b1eb895","repo":"apache/maven","slug":"path-url-reader-or-inputstream-must-be-non-null-c2d63e","errorCode":null,"errorMessage":"path, url, reader or inputStream must be non null","messagePattern":"path, url, reader or inputStream must be non null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java","lineNumber":56,"sourceCode":"import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxReader;\nimport org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxWriter;\n\nimport static java.util.Objects.requireNonNull;\nimport static org.apache.maven.impl.StaxLocation.getLocation;\nimport static org.apache.maven.impl.StaxLocation.getMessage;\n\n@Named\n@Singleton\npublic class DefaultPluginXmlFactory implements PluginXmlFactory {\n    @Override\n    public PluginDescriptor read(@Nonnull XmlReaderRequest request) throws XmlReaderException {\n        requireNonNull(request, \"request\");\n        Path path = request.getPath();\n        URL url = request.getURL();\n        Reader reader = request.getReader();\n        InputStream inputStream = request.getInputStream();\n        if (path == null && url == null && reader == null && inputStream == null) {\n            throw new IllegalArgumentException(\"path, url, reader or inputStream must be non null\");\n        }\n        try {\n            PluginDescriptorStaxReader xml = request.getTransformer() != null\n                    ? new PluginDescriptorStaxReader(request.getTransformer()::transform)\n                    : new PluginDescriptorStaxReader();\n            xml.setAddDefaultEntities(request.isAddDefaultEntities());\n            if (inputStream != null) {\n                return xml.read(inputStream, request.isStrict());\n            } else if (reader != null) {\n                return xml.read(reader, request.isStrict());\n            } else if (path != null) {\n                try (InputStream is = Files.newInputStream(path)) {\n                    return xml.read(is, request.isStrict());\n                }\n            } else {\n                try (InputStream is = url.openStream()) {\n                    return xml.read(is, request.isStrict());\n                }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java#L38-L74","documentation":"Thrown by DefaultPluginXmlFactory.read(XmlReaderRequest) when the request names no input: path, url, reader and inputStream are all null. The factory checks all four sources before parsing a PluginDescriptor (plugin.xml) and rejects the call immediately. This is a caller-contract violation.","triggerScenarios":"Building a XmlReaderRequest intended for a plugin descriptor without .path(...), .url(...), .reader(...) or .inputStream(...); setting only modelId, location or strict and forgetting the actual source.","commonSituations":"Copy-pasting request builders between the different XML factories; loading plugin.xml through a variable that turns out null; migrating code that opened the stream manually and lost that line in the port.","solutions":["Set exactly one input on the request: .inputStream(is), .reader(r), .path(p) or .url(u)","If the source is dynamic, check the four getters for null before calling read","Prefer .path or .url so the factory owns opening and closing the stream"],"exampleFix":"// before\nPluginDescriptor pd = pluginXmlFactory.read(XmlReaderRequest.builder()\n    .modelId(\"my.plugin:my-plugin:1.0\")\n    .build()); // throws: no input source\n\n// after\nPluginDescriptor pd = pluginXmlFactory.read(XmlReaderRequest.builder()\n    .modelId(\"my.plugin:my-plugin:1.0\")\n    .path(pluginXmlPath)\n    .build());","handlingStrategy":"validation","validationCode":"XmlReaderRequest req = XmlReaderRequest.builder()\n    .modelId(\"g:a:v\")\n    .build();\nif (req.getPath() == null && req.getURL() == null\n        && req.getReader() == null && req.getInputStream() == null) {\n    throw new IllegalStateException(\"plugin descriptor read request has no input source\");\n}\npluginXmlFactory.read(req);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the input source in the same builder chain as modelId so it cannot be forgotten","Prefer path or url sources so the factory handles stream closing"],"tags":["maven","xml","plugin-descriptor","reader","null-check"],"backgroundTag":"missing-required-argument","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}