FasterXML/jackson-databind · error · IllegalArgumentException
Cannot pass null modifier
Error message
Cannot pass null modifier
What it means
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.
Source
Thrown at src/main/java/tools/jackson/databind/cfg/DeserializerFactoryConfig.java:125
{
if (additional == null) {
throw new IllegalArgumentException("Cannot pass null KeyDeserializers");
}
KeyDeserializers[] all = ArrayBuilders.insertInListNoDup(_additionalKeyDeserializers, additional);
return new DeserializerFactoryConfig(_additionalDeserializers, all, _modifiers,
_valueInstantiators);
}
/**
* Fluent/factory method used to construct a configuration object that
* has same configuration as this instance plus one additional
* deserialiazer modifier. Added modifier has the highest priority (that is, it
* gets called before any already registered modifier).
*/
public DeserializerFactoryConfig withDeserializerModifier(ValueDeserializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Cannot pass null modifier");
}
ValueDeserializerModifier[] all = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new DeserializerFactoryConfig(_additionalDeserializers, _additionalKeyDeserializers,
all, _valueInstantiators);
}
/**
* Fluent/factory method used to construct a configuration object that
* has same configuration as this instance plus specified additional
* value instantiator provider object.
* Added instantiator provider has the highest priority (that is, it
* gets called before any already registered resolver).
*
* @param instantiators Object that can provide {@link tools.jackson.databind.deser.ValueInstantiator}s for
* constructing POJO values during deserialization
*/
public DeserializerFactoryConfig withValueInstantiators(ValueInstantiators instantiators)
{View on GitHub (pinned to a50c7d2a1d)
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.
Example fix
// before ValueDeserializerModifier mod = enableTweaks ? new MyModifier() : null; cfg.withDeserializerModifier(mod); // throws // after ValueDeserializerModifier mod = enableTweaks ? new MyModifier() : null; if (mod != null) cfg.withDeserializerModifier(mod);
Defensive patterns
Strategy: validation
Validate before calling
ValueDeserializerModifier mod = ...;
if (mod == null) throw new IllegalArgumentException("modifier must not be null");
cfg.withDeserializerModifier(mod); Type guard
// non-null reference check
Try / catch
try {
cfg.withDeserializerModifier(mod);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Cannot pass null modifier")) {
// skip modifier registration
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot pass null Deserializers
- Cannot pass null KeyDeserializers
- Cannot pass null resolver
- Module ({}) without defined name
- Module ({}) without defined version
AI-assisted analysis of FasterXML/jackson-databind@a50c7d2a1d (2026-08-06).
Data as JSON: /api/errors/b3ed26598ebb3893.
Report an issue: GitHub.