{"record":{"id":"ca7fa21ac1ef46d2","repo":"apache/maven","slug":"path-url-reader-or-inputstream-must-be-non-null","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/DefaultModelXmlFactory.java","lineNumber":98,"sourceCode":"        }\n        try {\n            String[] parts = version.split(\"\\\\.\");\n            int major = Integer.parseInt(parts[0]);\n            int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;\n            return major > 4 || (major == 4 && minor > 0);\n        } catch (NumberFormatException | IndexOutOfBoundsException e) {\n            return false;\n        }\n    }\n\n    @Nonnull\n    private Model doRead(XmlReaderRequest request) throws XmlReaderException {\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            String modelId = request.getModelId();\n            String location = request.getLocation();\n\n            if (modelId == null) {\n                if (inputStream != null) {\n                    ByteArrayOutputStream baos = new ByteArrayOutputStream();\n                    inputStream.transferTo(baos);\n                    byte[] buf = baos.toByteArray();\n                    modelId = extractModelId(new ByteArrayInputStream(buf));\n                    inputStream = new ByteArrayInputStream(buf);\n                } else if (reader != null) {\n                    CharArrayWriter caw = new CharArrayWriter();\n                    reader.transferTo(caw);\n                    char[] buf = caw.toCharArray();\n                    modelId = extractModelId(new CharArrayReader(buf));\n                    reader = new CharArrayReader(buf);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java#L80-L116","documentation":"DefaultModelXmlFactory.doRead requires the XmlReaderRequest to carry exactly one input source among path, URL, reader or inputStream. If all four are null it throws IllegalArgumentException immediately — there is nothing to read. Setting more than one is not validated the same way, but setting none is a hard caller error before any parsing starts.","triggerScenarios":"Building XmlReaderRequest with the builder but forgetting to call setPath/setInputStream/setReader/setURL (e.g. only setting modelId and strict), or passing a request whose input fields were conditionally assigned and every branch skipped.","commonSituations":"Optional-input API design where the caller assumes the builder defaults to a file; refactoring that removes the setPath call; code that reads from 'either a file or a stream' where both branches are guarded by mutually exclusive wrong conditions.","solutions":["Always set one input source on the request, e.g. XmlReaderRequest.builder().path(pomPath)","Validate your variables before building: at least one of path/url/reader/inputStream must be non-null, and fail with your own descriptive message","Prefer setPath for files so the reader can report accurate locations"],"exampleFix":"// before\nXmlReaderRequest req = XmlReaderRequest.builder()\n        .modelId('test:g:a:1')\n        .strict(true)\n        .build(); // no input set\n\n// after\nXmlReaderRequest req = XmlReaderRequest.builder()\n        .path(pomPath)\n        .modelId('test:g:a:1')\n        .strict(true)\n        .build();","handlingStrategy":"validation","validationCode":"if (request.getPath() == null && request.getURL() == null\n        && request.getReader() == null && request.getInputStream() == null) {\n    throw new IllegalArgumentException('XmlReaderRequest needs a path, url, reader or inputStream');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set exactly one input source when building XmlReaderRequest","Prefer path-based reads for files to get accurate error locations","Guard 'either/or' input logic with an exhaustive else that fails loudly"],"tags":["maven","pom","xml","validation","programming-error"],"backgroundTag":"missing-input-source","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}