{"record":{"id":"0c0fd2c6c9fcc434","repo":"chinabugotech/hutool","slug":"set-value-of-error","errorCode":null,"errorMessage":"Set value of [{}] error!","messagePattern":"Set value of \\[(.+?)\\] error!","errorType":"exception","errorClass":"BeanException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java","lineNumber":318,"sourceCode":"\t\tif (false == override && null != getValue(bean)) {\n\t\t\treturn this;\n\t\t}\n\n\t\t// 当类型不匹配的时候，执行默认转换\n\t\tif (null != value) {\n\t\t\tfinal Class<?> propClass = getFieldClass();\n\t\t\tif (false == propClass.isInstance(value)) {\n\t\t\t\tvalue = Convert.convertWithCheck(propClass, value, null, ignoreError);\n\t\t\t}\n\t\t}\n\n\t\t// 属性赋值\n\t\tif (null != value || false == ignoreNull) {\n\t\t\ttry {\n\t\t\t\tthis.setValue(bean, value);\n\t\t\t} catch (Exception e) {\n\t\t\t\tif (false == ignoreError) {\n\t\t\t\t\tthrow new BeanException(e, \"Set value of [{}] error!\", getFieldName());\n\t\t\t\t}\n\t\t\t\t// 忽略注入失败\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t//------------------------------------------------------------------------------------ Private method start\n\n\t/**\n\t * 通过Getter和Setter方法中找到属性类型\n\t *\n\t * @param getter Getter方法\n\t * @param setter Setter方法\n\t * @return {@link Type}\n\t */\n\tprivate Type findPropType(Method getter, Method setter) {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java#L300-L336","documentation":"PropDesc.setValue path: when the underlying setter/field assignment throws and ignoreError is false, the exception is wrapped as a BeanException naming the field. This happens during property injection (copyProperties, bean populating) when a setter rejects its value. ignoreError=true suppresses and skips the property.","triggerScenarios":"A setter that throws IllegalArgumentException for certain values; type-conversion failure that Convert.convertWithCheck could not handle (returns null) combined with a setter that rejects null; field assignment to a final field via reflection being blocked.","commonSituations":"copyProperties between beans with incompatible setter behaviour; populating beans from untrusted maps where a setter enforces constraints; records without matching setters.","solutions":["Enable ignoreError on the copy options to skip the failing field.","Align the source value type with the setter's expectation or pre-normalise values.","Exclude the field via ignoreProperties."],"exampleFix":"// before\nBeanUtil.fillBean(bean, valueProvider);\n// after\nBeanUtil.copyProperties(src, Target.class, CopyOptions.create().setIgnoreError(true).setIgnoreProperties(\"badField\"));","handlingStrategy":"validation","validationCode":"BeanUtil.copyProperties(src, T.class, CopyOptions.create().setIgnoreError(true).setIgnoreProperties(\"badField\"));","typeGuard":null,"tryCatchPattern":"try { prop.setValue(bean, value, false); } catch (BeanException e) { prop.setValue(bean, value, true); }","preventionTips":["Pre-normalize values to match setter expectations.","Use CopyOptions ignoreError/ignoreProperties for robust bean copying."],"tags":["bean","propdesc","reflection"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}