apache/maven · error · IllegalArgumentException
reader or inputStream must be non null
Error message
reader or inputStream must be non null
What it means
DefaultToolchainsXmlFactory.read accepts only a Reader or an InputStream; path and url on the request are not consulted. If both reader and inputStream are null it throws IllegalArgumentException before parsing a PersistedToolchains document.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsXmlFactory.java:55
import org.apache.maven.api.toolchain.InputSource;
import org.apache.maven.api.toolchain.PersistedToolchains;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxWriter;
import static java.util.Objects.requireNonNull;
import static org.apache.maven.impl.StaxLocation.getLocation;
import static org.apache.maven.impl.StaxLocation.getMessage;
@Named
@Singleton
public class DefaultToolchainsXmlFactory implements ToolchainsXmlFactory {
@Override
public PersistedToolchains read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
Objects.requireNonNull(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());
}
MavenToolchainsStaxReader xml = request.getTransformer() != null
? new MavenToolchainsStaxReader(request.getTransformer()::transform)
: new MavenToolchainsStaxReader();
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 toolchains: " + getMessage(e), getLocation(e), e);
}View on GitHub (pinned to e4093d4e12)
Solutions
- Open the file and pass .inputStream(Files.newInputStream(path)) or .reader(Files.newBufferedReader(path))
- Check getReader()/getInputStream() for null before calling read
Example fix
// before
PersistedToolchains t = toolchainsXmlFactory.read(XmlReaderRequest.builder()
.path(toolchainsPath) // ignored: wants reader or inputStream
.build()); // throws
// after\ntry (InputStream is = Files.newInputStream(toolchainsPath)) {\n PersistedToolchains t = toolchainsXmlFactory.read(XmlReaderRequest.builder()\n .inputStream(is)\n .build());\n} Defensive patterns
Strategy: validation
Validate before calling
XmlReaderRequest req = XmlReaderRequest.builder().build();
if (req.getReader() == null && req.getInputStream() == null) {
try (InputStream is = Files.newInputStream(toolchainsPath)) {
toolchainsXmlFactory.read(XmlReaderRequest.builder()
.inputStream(is)
.build());
}
} else {
toolchainsXmlFactory.read(req);
} Prevention
- This factory ignores path and url: always open the stream yourself
- Share one request-building helper for settings and toolchains reads
When it happens
Trigger: Building a XmlReaderRequest for toolchains with only .path(...) or .url(...) set (ignored by this factory), or with no source at all.
Common situations: Reusing request-builder code from factories that do support path/url; assuming the XML factory APIs are symmetric across model, plugin, settings and toolchains.
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
- reader or inputStream must be non null
- writer or outputStream must be non null
- Cannot read toolchains file at " + userToolchainsFile.getAbs
- writer, outputStream or path must be non null
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/783a8844c60ba825.
Report an issue: GitHub.