{"record":{"id":"d67410134cfc343d","repo":"FasterXML/jackson-databind","slug":"should-never-call-set-on-setterless-property","errorCode":null,"errorMessage":"Should never call `set()` on setterless property ('${getName()}')","messagePattern":"Should never call `set\\(\\)` on setterless property \\('(.+?)'\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/impl/SetterlessProperty.java","lineNumber":149,"sourceCode":"        // we get JSON null might be compatible. If so, implementation could be changed.\n        if (toModify == null) {\n            ctxt.reportBadDefinition(getType(), \"Problem deserializing 'setterless' property '%s': get method returned null\".formatted(\n                    getName()));\n        }\n        _valueDeserializer.deserialize(p, ctxt, toModify);\n    }\n\n    @Override\n    public Object deserializeSetAndReturn(JsonParser p,\n    \t\tDeserializationContext ctxt, Object instance) throws JacksonException\n    {\n        deserializeAndSet(p, ctxt, instance);\n        return instance;\n    }\n\n    @Override\n    public final void set(DeserializationContext ctxt, Object instance, Object value) {\n        throw new UnsupportedOperationException(\"Should never call `set()` on setterless property ('\"+getName()+\"')\");\n    }\n\n    @Override\n    public Object setAndReturn(DeserializationContext ctxt, Object instance, Object value)\n    {\n        set(ctxt, instance, value);\n        return instance;\n    }\n}","sourceCodeStart":131,"sourceCodeEnd":158,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/deser/impl/SetterlessProperty.java#L131-L158","documentation":"SetterlessProperty models a read-only Collection/Map property: deserialization works by calling the getter to obtain the existing collection and then populating it. The set() method is intentionally disabled because there is no setter to invoke; calling it is a programming error (the property was never meant to receive a value directly).","triggerScenarios":"Custom code or framework logic that calls SettableBeanProperty.set() on every property indiscriminately, hitting a setterless one; a JSON payload that triggers a code path attempting to assign a new collection to a getter-only field; misuse through reflection.","commonSituations":"A property exposed only via a getter returning a pre-initialized collection (e.g. private final List<X> items = new ArrayList<>(); with getItems()); code that tries to set rather than modify; using @JsonProperty on a getter-only member with a framework expecting a setter.","solutions":["Expose a setter or field for the property if direct assignment is required.","If populating in place is intended, ensure the deserializer goes through deserializeAndSet (which calls the getter and modifies the returned collection), not set().","Filter out SetterlessProperty instances from generic property-iteration code that calls set().","Add @JsonIgnore to the getter or annotate the field appropriately to avoid the property being treated as settable."],"exampleFix":"// before (framework code)\nfor (SettableBeanProperty p : props) {\n    p.set(ctxt, bean, value); // throws on setterless property\n}\n\n// after (skip setterless, or use deserializeAndSet)\nfor (SettableBeanProperty p : props) {\n    if (!(p instanceof SetterlessProperty)) {\n        p.set(ctxt, bean, value);\n    }\n}","handlingStrategy":"type-guard","validationCode":"if (p instanceof SetterlessProperty) {\n    // do not call set(); use deserializeAndSet or skip\n    return;\n}","typeGuard":"static boolean isSettable(SettableBeanProperty p) {\n    return !(p instanceof SetterlessProperty);\n}","tryCatchPattern":"try { p.set(ctxt, bean, value); }\ncatch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"setterless property\")) {\n        // add a setter/field, or skip this property\n    } else throw e;\n}","preventionTips":["In generic property-iteration code, skip SetterlessProperty instances when calling set().","If a property must be directly assignable, expose a setter or annotate the field."],"tags":["deserialization","setterless","read-only-property","unsupported-operation"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}