{"record":{"id":"2e085288a1d36974","repo":"FasterXML/jackson-databind","slug":"cannot-pass-null-resolver-2e0852","errorCode":null,"errorMessage":"Cannot pass null resolver","messagePattern":"Cannot pass null resolver","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/cfg/MapperBuilder.java","lineNumber":1496,"sourceCode":"        return _this();\n    }\n\n    /**\n     * Method that may be used to remove all {@link DeserializationProblemHandler}s added\n     * to this builder (if any).\n     */\n    public B clearProblemHandlers() {\n        _problemHandlers = null;\n        return _this();\n    }\n\n    /**\n     * Method for inserting specified {@link AbstractTypeResolver} as the first resolver\n     * in chain of possibly multiple resolvers.\n     */\n    public B addAbstractTypeResolver(AbstractTypeResolver resolver) {\n        if (resolver == null) {\n            throw new IllegalArgumentException(\"Cannot pass null resolver\");\n        }\n        _abstractTypeResolvers = ArrayBuilders.insertInListNoDup(_abstractTypeResolvers, resolver);\n        return _this();\n    }\n\n    /*\n    /**********************************************************************\n    /* Changing settings, date/time\n    /**********************************************************************\n     */\n\n    /**\n     * Method for configuring the default {@link DateFormat} to use when serializing time\n     * values as Strings, and deserializing from JSON Strings.\n     * If you need per-request configuration, factory methods in\n     * {@link ObjectReader} and {@link ObjectWriter} instead.\n     */\n    public B defaultDateFormat(DateFormat f) {","sourceCodeStart":1478,"sourceCodeEnd":1514,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/cfg/MapperBuilder.java#L1478-L1514","documentation":"Thrown by MapperBuilder.addAbstractTypeResolver when the supplied resolver is null. The builder treats null as a programming error rather than a silent no-op, because silently skipping it would mask a wiring bug in the caller.","triggerScenarios":"Calling mapperBuilder.addAbstractTypeResolver(null), or passing a lookup/DI result that resolved to null (e.g. Optional.orElse(null) or an unset bean).","commonSituations":"Conditional configuration where the resolver only sometimes exists; a refactor that left a null in place; a DI container failing to inject the bean; a feature flag disabling the resolver but not the registration call.","solutions":["Guard the call site: only register the resolver when you hold a non-null instance.","If the resolver is optional, wrap the call in `if (resolver != null)` or Objects.requireNonNull first.","Fix the upstream lookup/DI so a real resolver is produced."],"exampleFix":"// before\nbuilder.addAbstractTypeResolver(maybeResolver()); // maybeResolver() returns null -> throws\n// after\nAbstractTypeResolver resolver = maybeResolver();\nif (resolver != null) {\n    builder.addAbstractTypeResolver(resolver);\n}","handlingStrategy":"validation","validationCode":"AbstractTypeResolver resolver = obtainResolver();\nObjects.requireNonNull(resolver, \"AbstractTypeResolver must not be null\");\nbuilder.addAbstractTypeResolver(resolver);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat builder add* methods as non-null APIs; never pass through possibly-null lookups.","Wrap conditional registration in `if (resolver != null)` when the resolver is genuinely optional.","Use Objects.requireNonNull at the call site to fail fast with a clear message."],"tags":["configuration","null-check","abstract-type-resolver"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}