apache/maven · error · IllegalArgumentException
reader or inputStream must be non null
Error message
reader or inputStream must be non null
What it means
DefaultSettingsXmlFactory.read accepts only a Reader or an InputStream - unlike the model and plugin factories it does not consult path or url on the request. If both reader and inputStream are null it throws IllegalArgumentException before parsing.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java:53
import org.apache.maven.api.settings.InputLocation;
import org.apache.maven.api.settings.InputSource;
import org.apache.maven.api.settings.Settings;
import org.apache.maven.settings.v4.SettingsStaxReader;
import org.apache.maven.settings.v4.SettingsStaxWriter;
import static org.apache.maven.impl.StaxLocation.getLocation;
import static org.apache.maven.impl.StaxLocation.getMessage;
@Named
@Singleton
public class DefaultSettingsXmlFactory implements SettingsXmlFactory {
@Override
public Settings read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
nonNull(request, "request");
Reader reader = request.getReader();
InputStream inputStream = request.getInputStream();
if (reader == null && inputStream == null) {
throw new IllegalArgumentException("reader or inputStream must be non null");
}
try {
InputSource source = null;
if (request.getModelId() != null || request.getLocation() != null) {
source = InputSource.of(request.getLocation());
}
SettingsStaxReader xml = request.getTransformer() != null
? new SettingsStaxReader(request.getTransformer()::transform)
: new SettingsStaxReader();
xml.setAddDefaultEntities(request.isAddDefaultEntities());
if (reader != null) {
return xml.read(reader, request.isStrict(), source);
} else {
return xml.read(inputStream, request.isStrict(), source);
}
} catch (Exception e) {
throw new XmlReaderException("Unable to read settings: " + getMessage(e), getLocation(e), e);
}View on GitHub (pinned to e4093d4e12)
Solutions
- Open the source yourself and pass .inputStream(Files.newInputStream(path)) or .reader(Files.newBufferedReader(path))
- For URLs, use .inputStream(url.openStream()) and close it afterwards
- Check getReader()/getInputStream() for null before calling read
Example fix
// before
Settings s = settingsXmlFactory.read(XmlReaderRequest.builder()
.path(settingsPath) // ignored: this factory wants reader or inputStream
.build()); // throws
// after
try (InputStream is = Files.newInputStream(settingsPath)) {
Settings s = settingsXmlFactory.read(XmlReaderRequest.builder()
.inputStream(is)
.build());
} Defensive patterns
Strategy: validation
Validate before calling
XmlReaderRequest req = XmlReaderRequest.builder().build();
if (req.getReader() == null && req.getInputStream() == null) {
try (InputStream is = Files.newInputStream(settingsPath)) {
settingsXmlFactory.read(XmlReaderRequest.builder()
.inputStream(is)
.build());
}
} else {
settingsXmlFactory.read(req);
} Prevention
- Remember this factory ignores path and url: always open the stream yourself
- Keep one helper that builds settings read requests so the open-stream step is never skipped
When it happens
Trigger: Building a XmlReaderRequest for settings with only .path(...) or .url(...) set; those fields are ignored by this factory, so the call is rejected. Also a request with no source at all.
Common situations: Reusing request-builder code from DefaultModelXmlFactory or DefaultPluginXmlFactory, which do support path/url; developers assuming a symmetric API across all Maven XML factories.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- path, url, reader or inputStream must be non null
- writer or outputStream must be non null
- reader or inputStream must be non null
- writer, outputStream or path must be non null
- writer, outputStream or path must be non null
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/6c2326ec6eb2416a.
Report an issue: GitHub.