{"record":{"id":"b3ed26598ebb3893","repo":"FasterXML/jackson-databind","slug":"cannot-pass-null-modifier","errorCode":null,"errorMessage":"Cannot pass null modifier","messagePattern":"Cannot pass null modifier","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java","lineNumber":125,"sourceCode":"    {\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);\n        return new DeserializerFactoryConfig(_additionalDeserializers, _additionalKeyDeserializers,\n                all, _valueInstantiators);\n    }\n\n    /**\n     * Fluent/factory method used to construct a configuration object that\n     * has same configuration as this instance plus specified additional\n     * value instantiator provider object.\n     * Added instantiator provider has the highest priority (that is, it\n     * gets called before any already registered resolver).\n     *\n     * @param instantiators Object that can provide {@link tools.jackson.databind.deser.ValueInstantiator}s for\n     *    constructing POJO values during deserialization\n     */\n    public DeserializerFactoryConfig withValueInstantiators(ValueInstantiators instantiators)\n    {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java#L107-L143","documentation":"DeserializerFactoryConfig.withDeserializerModifier(ValueDeserializerModifier) registers a modifier that can post-process or replace deserializers built by the factory. It rejects null because the factory pipeline assumes a non-null modifier when iterating; a null would NPE during bean deserializer construction. This is the path SimpleModule.setDeserializerModifier and direct factory-config wiring use.","triggerScenarios":"Calling config.withDeserializerModifier(null); a module registering a modifier conditionally and forwarding null when disabled; a field that was supposed to hold a modifier but was never assigned due to a DI failure.","commonSituations":"Feature-flagged modifier registration; Spring/Hazelcast bean for the modifier missing; copy-paste of a module where the modifier argument was dropped; test setup that clears modifiers by passing null instead of building a fresh config.","solutions":["Only register when non-null: if (mod != null) cfg.withDeserializerModifier(mod).","Inject/construct the modifier eagerly; fail bean wiring if the dependency is missing.","To 'clear' modifiers, construct a fresh DeserializerFactoryConfig rather than passing null.","Add a unit test for your module asserting it never registers a null modifier."],"exampleFix":"// before\nValueDeserializerModifier mod = enableTweaks ? new MyModifier() : null;\ncfg.withDeserializerModifier(mod); // throws\n// after\nValueDeserializerModifier mod = enableTweaks ? new MyModifier() : null;\nif (mod != null) cfg.withDeserializerModifier(mod);","handlingStrategy":"validation","validationCode":"ValueDeserializerModifier mod = ...;\nif (mod == null) throw new IllegalArgumentException(\"modifier must not be null\");\ncfg.withDeserializerModifier(mod);","typeGuard":"// non-null reference check","tryCatchPattern":"try {\n    cfg.withDeserializerModifier(mod);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Cannot pass null modifier\")) {\n        // skip modifier registration\n    }\n    throw e;\n}","preventionTips":["Only register modifiers when non-null; build them eagerly.","To clear modifiers, build a fresh DeserializerFactoryConfig rather than passing null.","Unit-test module setup for null-safety."],"tags":["module","deserializer-modifier","factory-config","null-check","configuration"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}