{"record":{"id":"7802ab41bbd161fd","repo":"FasterXML/jackson-databind","slug":"argument-is-null","errorCode":null,"errorMessage":"argument \"{}\" is null","messagePattern":"argument \"(.+?)\" is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/ObjectWriter.java","lineNumber":1301,"sourceCode":"    }\n\n    /**\n     * Helper method that applies configured {@link GeneratorInitializer},\n     * if any, to the given generator and returns it.\n     *\n     * @since 3.2\n     */\n    protected JsonGenerator _initializeGenerator(JsonGenerator gen) {\n        GeneratorInitializer init = _config.getGeneratorInitializer();\n        if (init != null) {\n            init.initialize(_config, gen);\n        }\n        return gen;\n    }\n\n    protected final void _assertNotNull(String paramName, Object src) {\n        if (src == null){\n            throw new IllegalArgumentException(\"argument \\\"\" + paramName + \"\\\" is null\");\n        }\n    }\n\n    /*\n    /**********************************************************************\n    /* Helper classes for configuration\n    /**********************************************************************\n     */\n\n    /**\n     * As a minor optimization, we will make an effort to pre-fetch a serializer,\n     * or at least relevant <code>TypeSerializer</code>, if given enough\n     * information.\n     */\n    public final static class Prefetch\n        implements java.io.Serializable\n    {\n        @Serial","sourceCodeStart":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/ObjectWriter.java#L1283-L1319","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing a null OutputStream, Writer, File, or DataOutput to writeValue(). Forgetting to initialize an output target. Conditional code that may produce null output targets.","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."],"exampleFix":"// before\nOutputStream out = getStreamMaybeNull();\nwriter.writeValue(out, myObject); // throws if out is null\n// after\nOutputStream out = getStreamMaybeNull();\nif (out != null) writer.writeValue(out, myObject);\nelse throw new IllegalStateException(\"output stream was null\");","handlingStrategy":"validation","validationCode":"// Check for null before calling writer\nif (target == null) {\n    throw new IllegalArgumentException(\"output target must not be null\");\n}\nwriter.writeValue(target, value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Objects.requireNonNull(target, \"target\") before calling writeValue.","Initialize output streams/writers before the write call.","Avoid passing nullable references from conditional code."],"tags":["null-check","objectwriter","argument-validation","api-contract"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}