{"record":{"id":"720f5754dd38e755","repo":"apache/dubbo","slug":"object-is-null","errorCode":null,"errorMessage":"object is null","messagePattern":"object is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java","lineNumber":1385,"sourceCode":"    public static Set<String> getAllFieldNames(Class<?> type) {\n\n        Set<String> fieldNames = new HashSet<>();\n        for (Field field : type.getDeclaredFields()) {\n            fieldNames.add(field.getName());\n        }\n\n        Set<Class<?>> allSuperClasses = ClassUtils.getAllSuperClasses(type);\n        for (Class<?> aClass : allSuperClasses) {\n            for (Field field : aClass.getDeclaredFields()) {\n                fieldNames.add(field.getName());\n            }\n        }\n        return fieldNames;\n    }\n\n    public static <T> T getFieldValue(Object obj, String fieldName) throws RuntimeException {\n        if (obj == null) {\n            throw new IllegalArgumentException(\"object is null\");\n        }\n        try {\n            Field field = obj.getClass().getDeclaredField(fieldName);\n            field.setAccessible(true);\n            return (T) field.get(obj);\n        } catch (Exception e) {\n            throw new RuntimeException(e.getMessage(), e);\n        }\n    }\n}\n","sourceCodeStart":1367,"sourceCodeEnd":1396,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java#L1367-L1396","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nObject val = ReflectUtils.getFieldValue(maybeNullObj, \"fieldName\");\n\n// after\nif (maybeNullObj == null) {\n    return null; // or throw a domain-specific exception\n}\nObject val = ReflectUtils.getFieldValue(maybeNullObj, \"fieldName\");","handlingStrategy":"validation","validationCode":"if (obj == null) {\n    // skip or throw domain-specific exception\n    return;\n}\nObject val = ReflectUtils.getFieldValue(obj, fieldName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["reflection","null-check","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}