FasterXML/jackson-databind · error · IllegalArgumentException

Module ({}) without defined name

Error message

Module ({}) without defined name

What it means

MapperBuilder._verifyModuleMetadata() requires every JacksonModule being registered to report a non-null module name (and a non-null version). If a module's getModuleName() returns null, the builder throws IllegalArgumentException naming the module's class. This enforces that all registered modules are self-describing, which Jackson needs for module registry/deduplication and diagnostics.

Source

Thrown at src/main/java/tools/jackson/databind/cfg/MapperBuilder.java:1136

    }

    private void _addDependency(JacksonModule module)
    {
        _verifyModuleMetadata(module);
        final Object moduleId = module.getRegistrationId();
        if (_modules.containsKey(moduleId)) {
            return;
        }
        for (JacksonModule dep : module.getDependencies()) {
            _addDependency(dep);
        }
        _modules.put(moduleId, module);
    }

    private void _verifyModuleMetadata(JacksonModule module)
    {
        if (module.getModuleName() == null) {
            throw new IllegalArgumentException("Module ("+module.getClass().getName()+") without defined name");
        }
        if (module.version() == null) {
            throw new IllegalArgumentException("Module ("+module.getClass().getName()+") without defined version");
        }
    }

    public B addModules(JacksonModule... modules)
    {
        for (JacksonModule module : modules) {
            addModule(module);
        }
        return _this();
    }

    public B addModules(Iterable<? extends JacksonModule> modules)
    {
        for (JacksonModule module : modules) {
            addModule(module);

View on GitHub (pinned to a50c7d2a1d)

Solutions

  1. Give the module a name: new SimpleModule("myModule", PackageVersion.VERSION) or module.setModuleName("myModule").
  2. For a custom JacksonModule subclass, override getModuleName() to return a constant non-null string.
  3. If building modules generically, always pass a name in the constructor/builder.
  4. Add a test that asserts every module you publish returns a non-null name and version.

Example fix

// before
SimpleModule m = new SimpleModule(); // name may be null in 3.x
mapperBuilder.addModule(m); // throws
// after
SimpleModule m = new SimpleModule("myModule", Version.unknownVersion());
mapperBuilder.addModule(m);
Defensive patterns

Strategy: validation

Validate before calling

JacksonModule m = ...;
if (m.getModuleName() == null) throw new IllegalArgumentException("module name null: " + m.getClass());
mapperBuilder.addModule(m);

Type guard

boolean moduleHasName(JacksonModule m) {
    return m != null && m.getModuleName() != null && !m.getModuleName().isEmpty();
}

Try / catch

try {
    mapperBuilder.addModule(m);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("without defined name")) {
        // set a name and retry, or skip the module
    }
    throw e;
}

Prevention

When it happens

Trigger: Registering a module whose getModuleName() returns null; a module built via SimpleModule without calling setName()/withName(); a module class whose constructor doesn't seed the name; a dynamically-proxied or mock module that returns null for getModuleName().

Common situations: Creating a SimpleModule with the no-arg constructor (which historically defaulted a name) after a version change that made the default null; a test double/mock module; a module copied from 2.x where name defaults differed; a programmatically-constructed module that forgot the builder's name step.

Related errors


AI-assisted analysis of FasterXML/jackson-databind@a50c7d2a1d (2026-08-06). Data as JSON: /api/errors/8b389f41ec9b142b. Report an issue: GitHub.