{"record":{"id":"fd8c61aab6b03db1","repo":"chinabugotech/hutool","slug":"no-public-field-or-set-method-for","errorCode":null,"errorMessage":"No public field or set method for {}","messagePattern":"No public field or set method for (.+?)","errorType":"validation","errorClass":"BeanException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/bean/DynaBean.java","lineNumber":158,"sourceCode":"\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * 设置字段值\n\t *\n\t * @param fieldName 字段名\n\t * @param value     字段值\n\t * @throws BeanException 反射获取属性值或字段值导致的异常\n\t */\n\t@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n\tpublic void set(String fieldName, Object value) throws BeanException {\n\t\tif (Map.class.isAssignableFrom(beanClass)) {\n\t\t\t((Map) bean).put(fieldName, value);\n\t\t} else {\n\t\t\tfinal PropDesc prop = BeanUtil.getBeanDesc(beanClass).getProp(fieldName);\n\t\t\tif (null == prop) {\n\t\t\t\tthrow new BeanException(\"No public field or set method for {}\", fieldName);\n\t\t\t}\n\t\t\tprop.setValue(bean, value);\n\t\t}\n\t}\n\n\t/**\n\t * 执行原始Bean中的方法\n\t *\n\t * @param methodName 方法名\n\t * @param params     参数\n\t * @return 执行结果，可能为null\n\t */\n\tpublic Object invoke(String methodName, Object... params) {\n\t\treturn ReflectUtil.invoke(this.bean, methodName, params);\n\t}\n\n\t/**\n\t * 获得原始Bean","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/bean/DynaBean.java#L140-L176","documentation":"Mirror of error 30 for the set path: DynaBean.set resolves a PropDesc and throws BeanException if no public field or setter exists for the name. Map-backed beans route to Map.put and never hit this. The error means the property is read-only or non-existent on the class.","triggerScenarios":"dynaBean.set(\"readOnlyProp\", value) where the field has no setter and is not public; set(\"missing\", ...); setting a final field without a setter.","commonSituations":"Populating a bean from a map/config that contains keys with no writable counterpart; immutable DTOs with only getters; misaligned column-to-field mappings.","solutions":["Cross-check the name against getBeanDesc(...).getProps() filtering for writable properties.","Add a setter or make the field public for properties you intend to set dynamically.","Use a Map-backed DynaBean when you only need to store arbitrary key/values."],"exampleFix":"// before\ndynaBean.set(\"id\", value); // id is final, no setter\n// after\n// add `public void setId(...) { this.id = value; }` to the class, or use a Map-backed DynaBean","handlingStrategy":"validation","validationCode":"PropDesc p = BeanUtil.getBeanDesc(bean.getClass()).getProp(name);\nif (p == null || p.getSetter() == null && (p.getField()==null||!Modifier.isPublic(p.getField().getModifiers()))) throw new IllegalStateException(\"no writable property: \" + name);","typeGuard":"static boolean isWritable(BeanClass c, String f) { PropDesc p = BeanUtil.getBeanDesc(c).getProp(f); return p != null && (p.getSetter()!=null || (p.getField()!=null && Modifier.isPublic(p.getField().getModifiers()))); }","tryCatchPattern":"try { dynaBean.set(name, value); } catch (BeanException e) { /* skip unwritable */ }","preventionTips":["Ensure target fields have setters or are public before dynamic set.","Exclude unmappable keys when filling beans from external maps."],"tags":["bean","dynabean","reflection"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}