{"record":{"id":"ef7b040afa547f18","repo":"apache/dubbo","slug":"failed-to-set-pojo-dest-getclass-getsimplename","errorCode":null,"errorMessage":"Failed to set pojo ${dest.getClass().getSimpleName()} property ${name} value ${value.getClass()}, cause: ${e.getMessage()}","messagePattern":"Failed to set pojo (.+?) property (.+?) value (.+?), cause: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java","lineNumber":610,"sourceCode":"                                        value = realize1(\n                                                value, (Class<?>) containType, containType, mapGeneric, history);\n                                    } else {\n                                        Type ptype = method.getGenericParameterTypes()[0];\n                                        value = realize1(\n                                                value, method.getParameterTypes()[0], ptype, mapGeneric, history);\n                                    }\n                                } else {\n                                    Type ptype = method.getGenericParameterTypes()[0];\n                                    value = realize1(value, method.getParameterTypes()[0], ptype, mapGeneric, history);\n                                }\n                                try {\n                                    method.invoke(dest, value);\n                                } catch (Exception e) {\n                                    String exceptionDescription = \"Failed to set pojo \"\n                                            + dest.getClass().getSimpleName() + \" property \" + name + \" value \"\n                                            + value.getClass() + \", cause: \" + e.getMessage();\n                                    logger.error(COMMON_REFLECTIVE_OPERATION_FAILED, \"\", \"\", exceptionDescription, e);\n                                    throw new RuntimeException(exceptionDescription, e);\n                                }\n                            } else if (field != null) {\n                                value = realize1(value, field.getType(), field.getGenericType(), mapGeneric, history);\n                                try {\n                                    field.set(dest, value);\n                                } catch (IllegalAccessException e) {\n                                    throw new RuntimeException(\n                                            \"Failed to set field \" + name + \" of pojo \"\n                                                    + dest.getClass().getName() + \" : \" + e.getMessage(),\n                                            e);\n                                }\n                            }\n                        }\n                    }\n                }\n                return dest;\n            }\n        }","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java#L592-L628","documentation":"During realization (Map to POJO), PojoUtils finds a setter method for a property, realizes the value to the setter's parameter type, then invokes the setter via method.invoke(dest, value). If the invocation fails (type mismatch after realization, setter throws, access denied), the error is logged via logger.error with the COMMON_REFLECTIVE_OPERATION_FAILED code and then re-thrown as a RuntimeException with a descriptive message including the target class, property name, value class, and cause.","triggerScenarios":"Calling PojoUtils.realize(map, targetClass) where the Map contains a value for a property whose setter rejects the realized value — e.g. the setter expects Integer but the Map has a String that can't be converted, or the setter itself throws an IllegalArgumentException due to a business constraint.","commonSituations":"A generic Dubbo RPC where the consumer sends a field value whose type doesn't cleanly map to the provider's setter parameter type. Common when the provider DTO has strict types or validation in setters, or when the generic map representation uses incompatible types (e.g. BigDecimal vs Double).","solutions":["Check the exception message — it names the target class, property, and value class — to identify the mismatch.","Align the types in the source Map with the setter's expected parameter type before calling realize.","If the setter has validation logic, ensure the value passes that validation or fix the setter to be more lenient.","Consider using a custom TypeConverter or adjusting the provider DTO's setter to accept the incoming type."],"exampleFix":"// before — setter rejects mismatched type\npublic void setCount(Integer count) { this.count = count; }\n// incoming map: {\"count\": \"five\"}\n// after — ensure the map uses a compatible value\nmap.put(\"count\", 5);\n// or make the setter lenient\npublic void setCount(Object val) { this.count = Integer.parseInt(String.valueOf(val)); }","handlingStrategy":"try-catch","validationCode":"// Pre-validate setter compatibility before calling realize\nfor (Method setter : findSetters(dest.getClass())) {\n    String propName = getPropertyName(setter);\n    if (map.containsKey(propName)) {\n        Object val = map.get(propName);\n        Class<?> paramType = setter.getParameterTypes()[0];\n        if (val != null && !paramType.isAssignableFrom(val.getClass())\n                && !canConvert(val.getClass(), paramType)) {\n            throw new IllegalArgumentException(\n                \"Property '\" + propName + \"': cannot assign \" + val.getClass()\n                + \" to \" + paramType);\n        }\n    }\n}\nPojoUtils.realize(map, dest.getClass());","typeGuard":null,"tryCatchPattern":"try {\n    return PojoUtils.realize(map, targetClass);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to set pojo\")) {\n        logger.error(\"Property type mismatch during realization\", e);\n        // Log and rethrow or return partial result\n    }\n    throw e;\n}","preventionTips":["Ensure the generic Map representation uses types compatible with the target DTO setters.","Make setters lenient (accept Object, convert internally) if input types are unpredictable.","Validate the Map schema against the DTO class at integration test time."],"tags":["pojo","reflection","deserialization","setter-failure","type-mismatch"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}