apache/dubbo · error · RuntimeException
Failed to set field ${name} of pojo ${dest.getClass().getNam
Error message
Failed to set field ${name} of pojo ${dest.getClass().getName()} : ${e.getMessage()} What it means
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.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java:617
} else {
Type ptype = method.getGenericParameterTypes()[0];
value = realize1(value, method.getParameterTypes()[0], ptype, mapGeneric, history);
}
try {
method.invoke(dest, value);
} catch (Exception e) {
String exceptionDescription = "Failed to set pojo "
+ dest.getClass().getSimpleName() + " property " + name + " value "
+ value.getClass() + ", cause: " + e.getMessage();
logger.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", exceptionDescription, e);
throw new RuntimeException(exceptionDescription, e);
}
} else if (field != null) {
value = realize1(value, field.getType(), field.getGenericType(), mapGeneric, history);
try {
field.set(dest, value);
} catch (IllegalAccessException e) {
throw new RuntimeException(
"Failed to set field " + name + " of pojo "
+ dest.getClass().getName() + " : " + e.getMessage(),
e);
}
}
}
}
}
return dest;
}
}
return pojo;
}
/**
* Get key type for {@link Map} directly implemented by {@code clazz}.
* If {@code clazz} does not implement {@link Map} directly, return {@code null}.
*View on GitHub (pinned to 3a3043227f)
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.
Example fix
// before — module-info without opens
module com.example.dto { }
// after — open the package to Dubbo
module com.example.dto {
opens com.example.dto to org.apache.dubbo;
} Defensive patterns
Strategy: validation
Validate before calling
// Ensure module/package is open before realizing
// On JDK 9+: add 'opens com.example.dto;' in module-info.java
// Programmatically check field accessibility:
Class<?> target = dest.getClass();
for (Field f : target.getDeclaredFields()) {
if (!Modifier.isPublic(f)) {
try { f.setAccessible(true); }
catch (Exception ex) {
throw new IllegalStateException(
"Field " + f.getName() + " is not accessible in " + target.getName()
+ ". Add 'opens' to module-info or make public.", ex);
}
}
} Try / catch
try {
return PojoUtils.realize(map, targetClass);
} catch (RuntimeException e) {
if (e.getCause() instanceof IllegalAccessException) {
logger.error("Module access denied for {}. Add 'opens' directive.",
targetClass.getModuleName());
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to set pojo ${dest.getClass().getSimpleName()} proper
- Illegal constructor: ${cls.getName()}
- `name` filed should be string!
- Unrecognized Type: ${fieldType.toString()}
- Can not merge result because missing method [ {merger} ] in
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/28516e4fffa79a48.
Report an issue: GitHub.