{"record":{"id":"bd539588482fc1b4","repo":"apache/dubbo","slug":"cannot-find-field-s-field-is-null","errorCode":null,"errorMessage":"cannot find field %s,field is null","messagePattern":"cannot find field (.+?),field is null","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/FieldUtils.java","lineNumber":71,"sourceCode":"     *\n     * @param declaredClass the declared class\n     * @param fieldName     the name of {@link Field}\n     * @return if can't be found, return <code>null</code>\n     */\n    static Field findField(Class<?> declaredClass, String fieldName) {\n        Field field = getDeclaredField(declaredClass, fieldName);\n        if (field != null) {\n            return field;\n        }\n        for (Class superType : getAllInheritedTypes(declaredClass)) {\n            field = getDeclaredField(superType, fieldName);\n            if (field != null) {\n                break;\n            }\n        }\n\n        if (field == null) {\n            throw new IllegalStateException(String.format(\"cannot find field %s,field is null\", fieldName));\n        }\n\n        return field;\n    }\n\n    /**\n     * Find the {@link Field} by the name in the specified class and its inherited types\n     *\n     * @param object    the object whose field should be modified\n     * @param fieldName the name of {@link Field}\n     * @return if can't be found, return <code>null</code>\n     */\n    static Field findField(Object object, String fieldName) {\n        return findField(object.getClass(), fieldName);\n    }\n\n    /**\n     * Get the value of the specified {@link Field}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/FieldUtils.java#L53-L89","documentation":"FieldUtils.findField traversed the declared class and all its inherited/super types and could not locate a field with the requested name, so it throws IllegalStateException. The lookup is by exact name only and does not consider type overloads.","triggerScenarios":"Calling FieldUtils.findField(clazz, fieldName) (or the object-based overload) with a field name that is misspelled, private to an unrelated class, stripped by obfuscation/proguard, or absent after a refactoring.","commonSituations":"Reflection-based mappers/configurators that reference field names as strings; code broken after a rename; AOT/native-image builds where fields were removed; accessing a field that only exists on a subclass while passing the superclass.","solutions":["Verify the exact field name against the class source/javadoc (case-sensitive)","Pass the class/interface that actually declares the field, or the most-derived concrete type","Disable aggressive obfuscation for the relevant classes, or add keep rules in native-image/proguard configs","Switch to a public getter/setter if the field is not meant to be accessed directly"],"exampleFix":"// before\nField f = FieldUtils.findField(MyConfig.class, \"timeoutMills\");\n// after\nField f = FieldUtils.findField(MyConfig.class, \"timeoutMillis\");","handlingStrategy":"validation","validationCode":"Class<?> c = MyConfig.class;\njava.util.List<java.lang.reflect.Field> all = new java.util.ArrayList<>();\nfor (Class<?> k = c; k != null; k = k.getSuperclass()) all.addAll(java.util.Arrays.asList(k.getDeclaredFields()));\nboolean exists = all.stream().anyMatch(f -> f.getName().equals(fieldName));","typeGuard":"static boolean fieldExists(Class<?> c, String name) {\n    for (Class<?> k = c; k != null; k = k.getSuperclass())\n        for (java.lang.reflect.Field f : k.getDeclaredFields())\n            if (f.getName().equals(name)) return true;\n    return false;\n}","tryCatchPattern":"try { Field f = FieldUtils.findField(c, name); }\ncatch (IllegalStateException e) { /* name wrong or obfuscated; verify against source */ }","preventionTips":["Pin field-name strings to constants near the declaring class","Add proguard/native-image keep rules for reflectively accessed classes"],"tags":["reflection","field","config"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}