{"record":{"id":"a5107e80ce5ea5f4","repo":"FasterXML/jackson-databind","slug":"cannot-pass-null-keydeserializers","errorCode":null,"errorMessage":"Cannot pass null KeyDeserializers","messagePattern":"Cannot pass null KeyDeserializers","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java","lineNumber":109,"sourceCode":"    {\n        if (additional == null) {\n            throw new IllegalArgumentException(\"Cannot pass null Deserializers\");\n        }\n        Deserializers[] all = ArrayBuilders.insertInListNoDup(_additionalDeserializers, additional);\n        return new DeserializerFactoryConfig(all, _additionalKeyDeserializers, _modifiers,\n                _valueInstantiators);\n    }\n\n    /**\n     * Fluent/factory method used to construct a configuration object that\n     * has same key deserializer providers as this instance, plus one specified\n     * as argument. Additional provider will be added before existing ones,\n     * meaning it has priority over existing definitions.\n     */\n    public DeserializerFactoryConfig withAdditionalKeyDeserializers(KeyDeserializers additional)\n    {\n        if (additional == null) {\n            throw new IllegalArgumentException(\"Cannot pass null KeyDeserializers\");\n        }\n        KeyDeserializers[] all = ArrayBuilders.insertInListNoDup(_additionalKeyDeserializers, additional);\n        return new DeserializerFactoryConfig(_additionalDeserializers, all, _modifiers,\n                _valueInstantiators);\n    }\n\n    /**\n     * Fluent/factory method used to construct a configuration object that\n     * has same configuration as this instance plus one additional\n     * deserialiazer modifier. Added modifier has the highest priority (that is, it\n     * gets called before any already registered modifier).\n     */\n    public DeserializerFactoryConfig withDeserializerModifier(ValueDeserializerModifier modifier)\n    {\n        if (modifier == null) {\n            throw new IllegalArgumentException(\"Cannot pass null modifier\");\n        }\n        ValueDeserializerModifier[] all = ArrayBuilders.insertInListNoDup(_modifiers, modifier);","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java#L91-L127","documentation":"Thrown by DeserializerFactoryConfig.withAdditionalKeyDeserializers(KeyDeserializers) when the argument is null. Key deserializers handle Map key conversion (e.g., String to enum keys); a null provider would cause NPEs during map deserialization, so it is rejected at registration time.","triggerScenarios":"Calling deserializerFactoryConfig.withAdditionalKeyDeserializers(null) directly, or via SimpleModule.set/addKeyDeserializer() internal wiring that resolves to null. Also triggered by Module.setup() implementations with conditional bugs.","commonSituations":"Custom modules that conditionally provide key deserializers and return null when the condition is not met. Refactoring that leaves a KeyDeserializers field uninitialized. Third-party module bugs.","solutions":["Pass a non-null KeyDeserializers instance. If you have no key deserializers, skip the call.","Use SimpleKeyDeserializers as a concrete non-null container even when empty.","Fix the upstream null source rather than suppressing the check."],"exampleFix":"// before\nKeyDeserializers kd = buildKeyDeserializersConditionally(); // may be null\nconfig.withAdditionalKeyDeserializers(kd); // throws\n// after\nKeyDeserializers kd = buildKeyDeserializersConditionally();\nif (kd != null) {\n    config.withAdditionalKeyDeserializers(kd);\n}","handlingStrategy":"validation","validationCode":"// Validate before calling\nif (keyDeserializers == null) {\n    throw new IllegalArgumentException(\"KeyDeserializers provider must not be null\");\n}\nconfig.withAdditionalKeyDeserializers(keyDeserializers);","typeGuard":"boolean isNonNullProvider(KeyDeserializers kd) {\n    return kd != null;\n}","tryCatchPattern":null,"preventionTips":["Use Objects.requireNonNull(kd, \"keyDeserializers\") before calling.","Guard conditional KeyDeserializers construction with null checks.","Prefer SimpleKeyDeserializers as an empty concrete type over null."],"tags":["deserializer-factory","module","null-check","key-deserializer","configuration"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}