apache/maven · error · IllegalArgumentException
writer or outputStream must be non null
Error message
writer or outputStream must be non null
What it means
DefaultSettingsXmlFactory.write accepts only a Writer or an OutputStream - there is no path support on this factory. If both are null the call is rejected with IllegalArgumentException before serialization starts.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java:81
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);
}
}
@Override
public void write(XmlWriterRequest<Settings> request) throws XmlWriterException {
nonNull(request, "request");
Settings content = nonNull(request.getContent(), "content");
OutputStream outputStream = request.getOutputStream();
Writer writer = request.getWriter();
if (writer == null && outputStream == null) {
throw new IllegalArgumentException("writer or outputStream must be non null");
}
try {
SettingsStaxWriter xmlWriter = new SettingsStaxWriter();
xmlWriter.setAddLocationInformation(false);
Function<Object, String> formatter = request.getInputLocationFormatter();
if (formatter != null) {
xmlWriter.setAddLocationInformation(true);
Function<InputLocation, String> adapter = formatter::apply;
xmlWriter.setStringFormatter(adapter);
}
if (writer != null) {
xmlWriter.write(writer, content);
} else {
xmlWriter.write(outputStream, content);
}
} catch (Exception e) {View on GitHub (pinned to e4093d4e12)
Solutions
- Pass .writer(...) or .outputStream(...) on the request
- To write a file, open it yourself: .outputStream(Files.newOutputStream(settingsPath)) inside try-with-resources
- For in-memory output use .writer(new StringWriter())
Example fix
// before
settingsXmlFactory.write(XmlWriterRequest.builder()
.content(settings)
.path(settingsPath) // no path support on this factory
.build()); // throws
// after
try (OutputStream os = Files.newOutputStream(settingsPath)) {
settingsXmlFactory.write(XmlWriterRequest.builder()
.content(settings)
.outputStream(os)
.build());
} Defensive patterns
Strategy: validation
Validate before calling
XmlWriterRequest<Settings> req = XmlWriterRequest.builder()
.content(settings)
.build();
if (req.getWriter() == null && req.getOutputStream() == null) {
throw new IllegalStateException("settings write request has no writer or outputStream");
}
settingsXmlFactory.write(req); Prevention
- Do not port .path(...) from the model factory: settings writes need an open stream
- Wrap file writes in try-with-resources so the stream closes even on failure
When it happens
Trigger: Building a write request for Settings with only .path(...) set (ignored here), or with no output target at all.
Common situations: Porting write code from the model factory, which does support path targets; tests that set only the content.
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
- writer, outputStream or path must be non null
- writer, outputStream or path must be non null
- reader or inputStream must be non null
- writer or outputStream must be non null
- path, url, reader or inputStream must be non null
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/d800d2b3a4e3fc5b.
Report an issue: GitHub.