{"record":{"id":"f8c41d92bd7e4282","repo":"chinabugotech/hutool","slug":"get-value-of-error","errorCode":null,"errorMessage":"Get value of [{}] error!","messagePattern":"Get value of \\[(.+?)\\] error!","errorType":"exception","errorClass":"BeanException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java","lineNumber":214,"sourceCode":"\t}\n\n\t/**\n\t * 获取属性值，自动转换属性值类型<br>\n\t * 首先调用字段对应的Getter方法获取值，如果Getter方法不存在，则判断字段如果为public，则直接获取字段值\n\t *\n\t * @param bean        Bean对象\n\t * @param targetType  返回属性值需要转换的类型，null表示不转换\n\t * @param ignoreError 是否忽略错误，包括转换错误和注入错误\n\t * @return this\n\t * @since 5.4.2\n\t */\n\tpublic Object getValue(Object bean, Type targetType, boolean ignoreError) {\n\t\tObject result = null;\n\t\ttry {\n\t\t\tresult = getValue(bean);\n\t\t} catch (Exception e) {\n\t\t\tif (false == ignoreError) {\n\t\t\t\tthrow new BeanException(e, \"Get value of [{}] error!\", getFieldName());\n\t\t\t}\n\t\t}\n\n\t\tif (null != result && null != targetType) {\n\t\t\t// 尝试将结果转换为目标类型，如果转换失败，返回null，即跳过此属性值。\n\t\t\t// 来自：issues#I41WKP@Gitee，当忽略错误情况下，目标类型转换失败应返回null\n\t\t\t// 如果返回原值，在集合注入时会成功，但是集合取值时会报类型转换错误\n\t\t\treturn Convert.convertWithCheck(targetType, result, null, ignoreError);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * 检查属性是否可读（即是否可以通过{@link #getValue(Object)}获取到值）\n\t *\n\t * @param checkTransient 是否检查Transient关键字或注解\n\t * @return 是否可读\n\t * @since 5.4.2","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java#L196-L232","documentation":"PropDesc.getValue(bean, targetType, ignoreError) invokes the underlying getter; if that getter throws (or reflection fails) and ignoreError is false, the exception is wrapped in a BeanException naming the field. With ignoreError true the failure is swallowed and the value is left null. This is the read-side counterpart of error 33.","triggerScenarios":"A getter that itself throws (e.g. computes lazily and NPEs); a field whose getter is inaccessible; copyProperties/bean-to-bean mapping where ignoreError was not enabled.","commonSituations":"BeanUtil.copyProperties between beans with a faulty getter; BeanUtil.beanToMap hitting a getter that throws on certain states; record/class mismatch.","solutions":["Pass ignoreError=true to the copy/map API (e.g. copyProperties(src, tgt, CopyOptions.create().setIgnoreError(true))) to skip the failing property.","Fix the throwing getter so it does not blow up on the input state.","Exclude the problematic property via CopyOptions ignoreProperties."],"exampleFix":"// before\nBeanUtil.copyProperties(src, Target.class);\n// after\nBeanUtil.copyProperties(src, Target.class, CopyOptions.create().setIgnoreError(true));","handlingStrategy":"validation","validationCode":"// use ignoreError=true on copy/map APIs to skip throwing getters\nBeanUtil.copyProperties(src, T.class, CopyOptions.create().setIgnoreError(true));","typeGuard":null,"tryCatchPattern":"try { return prop.getValue(bean, type, false); } catch (BeanException e) { return prop.getValue(bean, type, true); }","preventionTips":["Enable ignoreError when mapping beans with possibly-throwing getters.","Fix or exclude getters that throw on normal data states."],"tags":["bean","propdesc","reflection"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}