FasterXML/jackson-databind · error · IllegalArgumentException
argument " " is null
Error message
argument "{}" is null What it means
Thrown by ObjectWriter._assertNotNull() when a required non-null argument is passed as null to a public ObjectWriter method. This is a fast-fail guard at the API boundary to provide a clear, named-parameter error instead of a downstream NullPointerException.
Solutions
- Initialize the output target before calling the writer method.
- Add a null check in your code: if (out != null) writer.writeValue(out, value).
- Use Objects.requireNonNull(out, "outputStream") for a clearer contract.
Example fix
// before
OutputStream out = getStreamMaybeNull();
writer.writeValue(out, myObject); // throws if out is null
// after
OutputStream out = getStreamMaybeNull();
if (out != null) writer.writeValue(out, myObject);
else throw new IllegalStateException("output stream was null"); Defensive patterns
Strategy: validation
Validate before calling
// Check for null before calling writer
if (target == null) {
throw new IllegalArgumentException("output target must not be null");
}
writer.writeValue(target, value); Prevention
- Use Objects.requireNonNull(target, "target") before calling writeValue.
- Initialize output streams/writers before the write call.
- Avoid passing nullable references from conditional code.
When it happens
Trigger: Calling ObjectWriter methods like writeValue((OutputStream) null, value), writeValueAsString with a null generator target, or with((FormatSchema) null) on certain overloaded paths that route through _assertNotNull.
Common situations: Passing a null OutputStream, Writer, File, or DataOutput to writeValue(). Forgetting to initialize an output target. Conditional code that may produce null output targets.
Related errors
- argument " " is null
- Cannot pass null Deserializers
- Cannot pass null KeyDeserializers
- Cannot pass null modifier
- Cannot pass null resolver
AI-assisted analysis of FasterXML/jackson-databind@87876ca5c0 (2026-08-11).
Data as JSON: /api/errors/7802ab41bbd161fd.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/tools/jackson/databind/ObjectWriter.java:1301
}
/**
* Helper method that applies configured {@link GeneratorInitializer},
* if any, to the given generator and returns it.
*
* @since 3.2
*/
protected JsonGenerator _initializeGenerator(JsonGenerator gen) {
GeneratorInitializer init = _config.getGeneratorInitializer();
if (init != null) {
init.initialize(_config, gen);
}
return gen;
}
protected final void _assertNotNull(String paramName, Object src) {
if (src == null){
throw new IllegalArgumentException("argument \"" + paramName + "\" is null");
}
}
/*
/**********************************************************************
/* Helper classes for configuration
/**********************************************************************
*/
/**
* As a minor optimization, we will make an effort to pre-fetch a serializer,
* or at least relevant <code>TypeSerializer</code>, if given enough
* information.
*/
public final static class Prefetch
implements java.io.Serializable
{
@SerialView on GitHub (pinned to 87876ca5c0)