{"record":{"id":"108cfb7f4b699f98","repo":"spring-projects/spring-framework","slug":"could-not-copy-property-targetpd-getname-fro","errorCode":null,"errorMessage":"Could not copy property '{targetPd.getName()}' from source to target","messagePattern":"Could not copy property '(.+?)' from source to target","errorType":"exception","errorClass":"FatalBeanException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/BeanUtils.java","lineNumber":831,"sourceCode":"\t\t\t\tCachedIntrospectionResults.forClass(source.getClass()) : null);\n\n\t\tfor (PropertyDescriptor targetPd : targetPds) {\n\t\t\tMethod writeMethod = targetPd.getWriteMethod();\n\t\t\tif (writeMethod != null && (ignoredProps == null || !ignoredProps.contains(targetPd.getName()))) {\n\t\t\t\tPropertyDescriptor sourcePd = (sourceResults != null ?\n\t\t\t\t\t\tsourceResults.getPropertyDescriptor(targetPd.getName()) : targetPd);\n\t\t\t\tif (sourcePd != null) {\n\t\t\t\t\tMethod readMethod = sourcePd.getReadMethod();\n\t\t\t\t\tif (readMethod != null) {\n\t\t\t\t\t\tif (isAssignable(writeMethod, readMethod, sourcePd, targetPd)) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tReflectionUtils.makeAccessible(readMethod);\n\t\t\t\t\t\t\t\tObject value = readMethod.invoke(source);\n\t\t\t\t\t\t\t\tReflectionUtils.makeAccessible(writeMethod);\n\t\t\t\t\t\t\t\twriteMethod.invoke(target, value);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (Throwable ex) {\n\t\t\t\t\t\t\t\tthrow new FatalBeanException(\n\t\t\t\t\t\t\t\t\t\t\"Could not copy property '\" + targetPd.getName() + \"' from source to target\", ex);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static boolean isAssignable(Method writeMethod, Method readMethod,\n\t\t\tPropertyDescriptor sourcePd, PropertyDescriptor targetPd) {\n\n\t\tType paramType = writeMethod.getGenericParameterTypes()[0];\n\t\tif (paramType instanceof Class<?> clazz) {\n\t\t\treturn ClassUtils.isAssignable(clazz, readMethod.getReturnType());\n\t\t}\n\t\telse if (paramType.equals(readMethod.getGenericReturnType())) {\n\t\t\treturn true;","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java#L813-L849","documentation":"Thrown as a FatalBeanException from the copyProperties loop when invoking either the source's read method or the target's write method throws anything (Throwable). Spring wraps the underlying reflection failure (e.g. IllegalAccessException, InvocationTargetException wrapping an NPE, type incompatibility) and names the property that failed.","triggerScenarios":"Inside BeanUtils.copyProperties, after isAssignable passes, the code calls readMethod.invoke(source) then writeMethod.invoke(target, value); if either throws, the catch(Throwable) wraps it in FatalBeanException with the offending targetPd.getName().","commonSituations":"A setter on the target throws an exception (validation, NPE on a converted null, unsupported value), the read method accesses a field that is lazily initialized and fails, a method became inaccessible under a strict module/SecurityManager setup, or value conversion between incompatible types at the reflective invoke level.","solutions":["Read the wrapped cause (getCause()/getRootCause()) of the FatalBeanException; the named property tells you which bean property failed.","Fix the setter/read-method logic so it no longer throws (null-checks, validation, default values).","Skip the offending property using the ignoreProperties varargs of copyProperties, or exclude it explicitly.","If the failure is an access restriction, ensure the methods are accessible (public getters/setters, open module via --add-opens)."],"exampleFix":"// before\nBeanUtils.copyProperties(src, target);\n// setter 'setFoo' throws on null\n\n// after - ignore the problematic property\nBeanUtils.copyProperties(src, target, \"foo\");\n// or fix the setter to tolerate null","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    BeanUtils.copyProperties(src, target);\n} catch (FatalBeanException ex) {\n    // ex.getMessage() names the property that failed\n    Throwable cause = ex.getCause(); // the real reflective failure\n    log.warn(\"copy failed for property: {}\", ex.getMessage(), cause);\n}","preventionTips":["Keep getters/setters side-effect free and tolerant of null.","Use the ignoreProperties varargs to skip known-troublesome properties.","Always inspect getCause() of FatalBeanException - the wrapper hides the real reason."],"tags":["bean-utils","copy-properties","reflection","spring-beans"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}