apache/dubbo · error · IllegalArgumentException
object is null
Error message
object is null
What it means
Thrown by ReflectUtils.getFieldValue(Object, String) when the obj argument is null. The method uses reflection to read a declared field by name from the object's class, so a null target has no class to reflect on. This is a precondition violation — the method explicitly guards against null before attempting any field access.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java:1385
public static Set<String> getAllFieldNames(Class<?> type) {
Set<String> fieldNames = new HashSet<>();
for (Field field : type.getDeclaredFields()) {
fieldNames.add(field.getName());
}
Set<Class<?>> allSuperClasses = ClassUtils.getAllSuperClasses(type);
for (Class<?> aClass : allSuperClasses) {
for (Field field : aClass.getDeclaredFields()) {
fieldNames.add(field.getName());
}
}
return fieldNames;
}
public static <T> T getFieldValue(Object obj, String fieldName) throws RuntimeException {
if (obj == null) {
throw new IllegalArgumentException("object is null");
}
try {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return (T) field.get(obj);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
View on GitHub (pinned to 3a3043227f)
Solutions
- Null-check the object before calling getFieldValue: if (obj != null) { ReflectUtils.getFieldValue(obj, name); }
- Trace where the null originated — inspect the upstream lookup (Map, cache, or bean wiring) that produced the value.
- If the field may legitimately be absent, catch RuntimeException and inspect the cause for NoSuchFieldException.
Example fix
// before
Object val = ReflectUtils.getFieldValue(maybeNullObj, "fieldName");
// after
if (maybeNullObj == null) {
return null; // or throw a domain-specific exception
}
Object val = ReflectUtils.getFieldValue(maybeNullObj, "fieldName"); Defensive patterns
Strategy: validation
Validate before calling
if (obj == null) {
// skip or throw domain-specific exception
return;
}
Object val = ReflectUtils.getFieldValue(obj, fieldName); Prevention
- Always null-check objects obtained from Map.get(), Optional, or service lookups before passing to reflection utilities.
- Use Objects.requireNonNull(obj, "target object") at the call site to get a clearer message.
When it happens
Trigger: Calling ReflectUtils.getFieldValue(null, "fieldName") or passing a variable that evaluated to null as the first argument. Common when the caller obtained the object from a Map.get(), optional, or service lookup that returned null and did not check.
Common situations: Deserializing or inspecting an object whose source (e.g. a cached value, RPC response, or Spring bean) was not populated; test helpers that pass a mock that returned null; refactoring that changed a factory method to return null on missing data.
Related errors
- unable to determine bean class from factory's superclass or
- create bean instance failed, type=${className}
- Expect only one but found ${size} matched constructors for t
- None matched constructor was found for type: ${type}
- class == null
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/720f5754dd38e755.
Report an issue: GitHub.