apache/maven · error · IllegalArgumentException
path, url, reader or inputStream must be non null
Error message
path, url, reader or inputStream must be non null
What it means
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.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:98
}
try {
String[] parts = version.split("\\.");
int major = Integer.parseInt(parts[0]);
int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
return major > 4 || (major == 4 && minor > 0);
} catch (NumberFormatException | IndexOutOfBoundsException e) {
return false;
}
}
@Nonnull
private Model doRead(XmlReaderRequest request) throws XmlReaderException {
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");
}
try {
String modelId = request.getModelId();
String location = request.getLocation();
if (modelId == null) {
if (inputStream != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
inputStream.transferTo(baos);
byte[] buf = baos.toByteArray();
modelId = extractModelId(new ByteArrayInputStream(buf));
inputStream = new ByteArrayInputStream(buf);
} else if (reader != null) {
CharArrayWriter caw = new CharArrayWriter();
reader.transferTo(caw);
char[] buf = caw.toCharArray();
modelId = extractModelId(new CharArrayReader(buf));
reader = new CharArrayReader(buf);View on GitHub (pinned to e4093d4e12)
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
Example fix
// before
XmlReaderRequest req = XmlReaderRequest.builder()
.modelId('test:g:a:1')
.strict(true)
.build(); // no input set
// after
XmlReaderRequest req = XmlReaderRequest.builder()
.path(pomPath)
.modelId('test:g:a:1')
.strict(true)
.build(); Defensive patterns
Strategy: validation
Validate before calling
if (request.getPath() == null && request.getURL() == null
&& request.getReader() == null && request.getInputStream() == null) {
throw new IllegalArgumentException('XmlReaderRequest needs a path, url, reader or inputStream');
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to read model:
- Repository identifier missing
- URL missing for repository " + id
- Repository identifier missing
- URL missing for repository {}
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/ca7fa21ac1ef46d2.
Report an issue: GitHub.