{"record":{"id":"920ca1ee467b3b9a","repo":"FasterXML/jackson-databind","slug":"anysetter-already-set-to-non-null","errorCode":null,"errorMessage":"_anySetter already set to non-null","messagePattern":"_anySetter already set to non-null","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/BeanDeserializerBuilder.java","lineNumber":299,"sourceCode":"    /**\n     * Method called by deserializer factory, when a \"creator property\"\n     * (something that is passed via constructor- or factory method argument;\n     * instead of setter or field).\n     *<p>\n     * Default implementation does not do anything; we may need to revisit this\n     * decision if these properties need to be available through accessors.\n     * For now, however, we just have to ensure that we don't try to resolve\n     * types that masked setter/field has (see [JACKSON-700] for details).\n     */\n    public void addCreatorProperty(SettableBeanProperty prop)\n    {\n        addProperty(prop);\n    }\n\n    public void setAnySetter(SettableAnyProperty s)\n    {\n        if (_anySetter != null && s != null) {\n            throw new IllegalStateException(\"_anySetter already set to non-null\");\n        }\n        _anySetter = s;\n    }\n\n    public void setIgnoreUnknownProperties(boolean ignore) {\n        _ignoreAllUnknown = ignore;\n    }\n\n    public void setValueInstantiator(ValueInstantiator inst) {\n        _valueInstantiator = inst;\n        _propsBasedCreatorParams = inst.getFromObjectArguments(_config);\n    }\n\n    public void setObjectIdReader(ObjectIdReader r) {\n        _objectIdReader = r;\n    }\n\n    public void setPOJOBuilder(AnnotatedMethod buildMethod, JsonPOJOBuilder.Value config) {","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/deser/BeanDeserializerBuilder.java#L281-L317","documentation":"Thrown by BeanDeserializerBuilder.setAnySetter as IllegalStateException when setAnySetter is invoked twice with non-null values. A bean can have at most one 'any setter' (the catch-all for unknown properties, via @JsonAnySetter); encountering a second candidate means the type declares multiple any-setter members.","triggerScenarios":"A bean declares more than one @JsonAnySetter (e.g., a field of type Map plus a setter method, or two any-setter methods), causing the factory to call setAnySetter twice with non-null.","commonSituations":"Adding @JsonAnySetter to both a Map field and a method; refactoring a setter into a field but leaving the old annotation; mixins/merged types that collectively declare two any-setters; combining @JsonAnySetter with @JsonSetter on the same logical slot.","solutions":["Ensure the target type declares exactly one @JsonAnySetter member (typically a single-arg Map setter or a (String, Object) method).","Remove redundant @JsonAnySetter annotations after refactoring.","Check mixins applied to the type do not add a second any-setter."],"exampleFix":"// before: two any-setters\nclass Pojo {\n    @JsonAnySetter private Map<String,Object> extra;\n    @JsonAnySetter public void add(String k, Object v){...}\n}\n\n// after: single any-setter\nclass Pojo {\n    @JsonAnySetter public void add(String k, Object v){...}\n}","handlingStrategy":"validation","validationCode":"// Count @JsonAnySetter members on the type (and mixins).\nlong anySetters = Arrays.stream(cls.getDeclaredMethods())\n    .filter(m -> m.isAnnotationPresent(JsonAnySetter.class)).count();\nif (anySetters > 1) {\n    throw new IllegalStateException(cls + \" has multiple @JsonAnySetter methods\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare at most one @JsonAnySetter per type.","Remove stale @JsonAnySetter annotations after refactoring.","Check mixins for stray any-setter declarations."],"tags":["jackson","deserialization","bean","any-setter","annotation"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}