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

  1. Initialize the output target before calling the writer method.
  2. Add a null check in your code: if (out != null) writer.writeValue(out, value).
  3. 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

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


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
    {
        @Serial

View on GitHub (pinned to 87876ca5c0)