{"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/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java#L91-L127","documentation":"DeserializerFactoryConfig.withAdditionalKeyDeserializers(KeyDeserializers) registers an additional key-deserializer provider (used for Map keys) and rejects null to fail fast rather than NPE later during map key resolution. Modules that add custom Map key handling call this; a null provider would break the resolution chain silently.","triggerScenarios":"Calling config.withAdditionalKeyDeserializers(null); a module registering key deserializers conditionally and passing null when the feature is off; a collection/loop where one KeyDeserializers element is null.","commonSituations":"Module that adds key deserializers only for certain dataformats and forwards null otherwise; DI-provided KeyDeserializers bean null due to missing dependency; refactoring that left a registration call with a now-nullable field.","solutions":["Guard the registration: if (kd != null) cfg.withAdditionalKeyDeserializers(kd).","Construct the KeyDeserializers eagerly so it is never null at registration time.","Filter nulls from provider lists before the registration loop.","In module setup, log/skip a null rather than forwarding it."],"exampleFix":"// before\nKeyDeserializers kd = useCustomKeys ? new MyKeyDeserializers() : null;\ncfg.withAdditionalKeyDeserializers(kd); // throws\n// after\nKeyDeserializers kd = useCustomKeys ? new MyKeyDeserializers() : null;\nif (kd != null) cfg.withAdditionalKeyDeserializers(kd);","handlingStrategy":"validation","validationCode":"KeyDeserializers kd = ...;\nif (kd == null) throw new IllegalArgumentException(\"KeyDeserializers must not be null\");\ncfg.withAdditionalKeyDeserializers(kd);","typeGuard":"// non-null reference check","tryCatchPattern":"try {\n    cfg.withAdditionalKeyDeserializers(kd);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Cannot pass null KeyDeserializers\")) {\n        // skip registration or build a default\n    }\n    throw e;\n}","preventionTips":["Guard conditional registrations: if (kd != null) register.","Filter nulls from provider lists before iterating.","Construct key deserializer beans eagerly."],"tags":["module","key-deserializer","factory-config","null-check","configuration"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}