apache/maven · error · IllegalArgumentException
{} cannot be null
Error message
{} cannot be null What it means
Generic null guard used by DefaultSettingsXmlFactory for its request and content parameters; the message interpolates the parameter name, so it surfaces as 'request cannot be null' or 'content cannot be null'. read() rejects a null request; write() rejects a null request and a request whose getContent() is null.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java:106
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) {
throw new XmlWriterException("Unable to write settings: " + getMessage(e), getLocation(e), e);
}
}
static <T> T nonNull(T t, String name) {
if (t == null) {
throw new IllegalArgumentException(name + " cannot be null");
}
return t;
}
}
View on GitHub (pinned to e4093d4e12)
Solutions
- Always set .content(settings) on write requests
- Null-check the request object before the call
- Add your own requireNonNull checks earlier so failures carry your call-site context
Example fix
// before
settingsXmlFactory.write(XmlWriterRequest.builder()
.writer(sw)
.build()); // throws: content cannot be null
// after
settingsXmlFactory.write(XmlWriterRequest.builder()
.content(settings)
.writer(sw)
.build()); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(request, "request");
if (writing && request.getContent() == null) {
throw new IllegalStateException("settings write requires non-null content");
}
// now safe to call the factory Prevention
- Never pass Optional.orElse(null) results into the factory
- Set .content(...) in the same builder expression as the target
When it happens
Trigger: Passing a null XmlReaderRequest/XmlWriterRequest to read/write; calling write with a request built without .content(settings).
Common situations: Optional-based call chains that hand null through; builder refactors that drop the content line; helper methods that accept nullable requests.
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
- reader or inputStream must be non null
- writer or outputStream must be non null
- Illegal request type: " + requestType
- Illegal event type: " + eventType
- Repository identifier missing
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/804eb323bae56e8f.
Report an issue: GitHub.