{"record":{"id":"df281cda030727c9","repo":"FasterXML/jackson-databind","slug":"argument-s-is-null","errorCode":null,"errorMessage":"argument \"%s\" is null","messagePattern":"argument \"(.+?)\" is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/ObjectReader.java","lineNumber":2115,"sourceCode":"    }\n\n    /**\n     * Internal helper method called to create an instance of {@link DeserializationContext}\n     * for deserializing a single root value.\n     * Can be overridden if a custom context is needed.\n     */\n    protected DeserializationContextExt _deserializationContext() {\n        return _contexts.createContext(_config, _schema, _injectableValues);\n    }\n\n    protected DeserializationContextExt _deserializationContext(JsonParser p) {\n        return _contexts.createContext(_config, _schema, _injectableValues)\n                .assignParser(p);\n    }\n\n    protected final void _assertNotNull(String paramName, Object src) {\n        if (src == null){\n            throw new IllegalArgumentException(\"argument \\\"%s\\\" is null\".formatted(paramName));\n        }\n    }\n\n    /*\n    /**********************************************************************\n    /* Helper methods, locating deserializers etc\n    /**********************************************************************\n     */\n\n    /**\n     * Method called to locate deserializer for the passed root-level value.\n     */\n    protected ValueDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt)\n        throws DatabindException\n    {\n        if (_rootDeserializer != null) {\n            return _rootDeserializer;\n        }","sourceCodeStart":2097,"sourceCodeEnd":2133,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/ObjectReader.java#L2097-L2133","documentation":"ObjectReader._assertNotNull() is a precondition guard invoked by nearly every read/forType/readValue/readTree/etc. entry point (57 call sites) to fail fast with a clear message when a required argument is null. The message includes the parameter name (e.g. \"src\", \"content\", \"p\", \"type\") so you know exactly which argument was null. It replaces a latent NullPointerException deeper in the call with an explicit, descriptive IllegalArgumentException at the API boundary.","triggerScenarios":"Calling reader.readValue((String)null), reader.readTree((JsonParser)null), reader.forType((Class)null), reader.readValues((InputStream)null), etc. Common when the source variable comes from a map.get() that returned null, a resource lookup that failed, or a generically-typed parameter that the caller left null.","commonSituations":"A field/property that was optional in the source data but is passed unchecked; a Spring/Hazelcast/JNDI resource lookup returning null on misconfiguration and being forwarded directly; HTTP request body or path variable that is null when the endpoint receives no body; refactoring that moved a null check away from the call site.","solutions":["Check for null before calling read methods: Objects.requireNonNull(src, \"src\") or an explicit if/null branch.","If null is legitimately 'no input', handle it at the caller with an empty/Optional/default rather than passing it down.","Annotate the producing method/field with @NotNull / @NonNull and enable static null-analysis (Checker Framework, IntelliJ nullability, Eclipse null annotations).","Where the value comes from a Map or external source, use getOrDefault / Optional.ofNullable to guarantee non-null."],"exampleFix":"// before\nString body = request.getBody(); // may be null\nMyType v = reader.readValue(body); // throws: argument \"src\" is null\n// after\nString body = request.getBody();\nif (body == null) throw new BadRequestException(\"body required\");\nMyType v = reader.readValue(body);","handlingStrategy":"validation","validationCode":"String body = ...;\nif (body == null) throw new IllegalArgumentException(\"src must not be null\");\nreader.readValue(body);","typeGuard":"// simple non-null check is the guard; for collections, check emptiness too","tryCatchPattern":"try {\n    return reader.readValue(src);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().endsWith(\"is null\")) {\n        // provide a domain-meaningful default or 4xx response\n    }\n    throw e;\n}","preventionTips":["Null-check at the controller/service boundary before calling read methods.","Use Optional and serialize only when present.","Enable static null analysis (@NonNull annotations) to catch null flows at compile time.","Prefer Objects.requireNonNull(src, \"src\") for clear precondition failures."],"tags":["object-reader","null-check","precondition","api-misuse"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}