{"record":{"id":"28516e4fffa79a48","repo":"apache/dubbo","slug":"failed-to-set-field-name-of-pojo-dest-getclas","errorCode":null,"errorMessage":"Failed to set field ${name} of pojo ${dest.getClass().getName()} : ${e.getMessage()}","messagePattern":"Failed to set field (.+?) of pojo (.+?) : (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java","lineNumber":617,"sourceCode":"                                } 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        }\n        return pojo;\n    }\n\n    /**\n     * Get key type for {@link Map} directly implemented by {@code clazz}.\n     * If {@code clazz} does not implement {@link Map} directly, return {@code null}.\n     *","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java#L599-L635","documentation":"During realization, if no setter method is found for a property but a public field exists, PojoUtils uses field.set(dest, value) to assign the value directly. If this throws IllegalAccessException, it is wrapped in a RuntimeException naming the field and the target POJO class. This is distinct from error 268 which covers the method.invoke path.","triggerScenarios":"Calling PojoUtils.realize where the target object has a field (rather than a setter) for a property, and the field is not reflectively accessible — e.g. a non-public field in a class from another module without 'opens' declaration, or a SecurityManager that denies access even after makeAccessible.","commonSituations":"JDK 9+ module system where the target class's module does not 'opens' the package to Dubbo. Also when the class was loaded by a different classloader. The field-based assignment path is a fallback used when the class has no setter for the property.","solutions":["Add an 'opens <package>;' directive in module-info.java for the target class's module so Dubbo can access fields reflectively.","Add a standard setter for the property so PojoUtils uses method.invoke instead of field.set.","If using a SecurityManager, grant the necessary ReflectPermission.","Make the field public as a last resort."],"exampleFix":"// before — module-info without opens\nmodule com.example.dto { }\n// after — open the package to Dubbo\nmodule com.example.dto {\n    opens com.example.dto to org.apache.dubbo;\n}","handlingStrategy":"validation","validationCode":"// Ensure module/package is open before realizing\n// On JDK 9+: add 'opens com.example.dto;' in module-info.java\n// Programmatically check field accessibility:\nClass<?> target = dest.getClass();\nfor (Field f : target.getDeclaredFields()) {\n    if (!Modifier.isPublic(f)) {\n        try { f.setAccessible(true); }\n        catch (Exception ex) {\n            throw new IllegalStateException(\n                \"Field \" + f.getName() + \" is not accessible in \" + target.getName()\n                + \". Add 'opens' to module-info or make public.\", ex);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return PojoUtils.realize(map, targetClass);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IllegalAccessException) {\n        logger.error(\"Module access denied for {}. Add 'opens' directive.\",\n            targetClass.getModuleName());\n    }\n    throw e;\n}","preventionTips":["Add standard JavaBean setters for all properties so PojoUtils uses method.invoke (not field.set).","On JDK 9+, add 'opens <package>;' in module-info for all DTO packages.","Avoid relying on public fields for properties that cross serialization boundaries."],"tags":["pojo","reflection","deserialization","field-access","module-system"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}