apache/dubbo · error · IllegalStateException

cannot find field %s,field is null

Error message

cannot find field %s,field is null

What it means

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.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/FieldUtils.java:71

     *
     * @param declaredClass the declared class
     * @param fieldName     the name of {@link Field}
     * @return if can't be found, return <code>null</code>
     */
    static Field findField(Class<?> declaredClass, String fieldName) {
        Field field = getDeclaredField(declaredClass, fieldName);
        if (field != null) {
            return field;
        }
        for (Class superType : getAllInheritedTypes(declaredClass)) {
            field = getDeclaredField(superType, fieldName);
            if (field != null) {
                break;
            }
        }

        if (field == null) {
            throw new IllegalStateException(String.format("cannot find field %s,field is null", fieldName));
        }

        return field;
    }

    /**
     * Find the {@link Field} by the name in the specified class and its inherited types
     *
     * @param object    the object whose field should be modified
     * @param fieldName the name of {@link Field}
     * @return if can't be found, return <code>null</code>
     */
    static Field findField(Object object, String fieldName) {
        return findField(object.getClass(), fieldName);
    }

    /**
     * Get the value of the specified {@link Field}

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Verify the exact field name against the class source/javadoc (case-sensitive)
  2. Pass the class/interface that actually declares the field, or the most-derived concrete type
  3. Disable aggressive obfuscation for the relevant classes, or add keep rules in native-image/proguard configs
  4. Switch to a public getter/setter if the field is not meant to be accessed directly

Example fix

// before
Field f = FieldUtils.findField(MyConfig.class, "timeoutMills");
// after
Field f = FieldUtils.findField(MyConfig.class, "timeoutMillis");
Defensive patterns

Strategy: validation

Validate before calling

Class<?> c = MyConfig.class;
java.util.List<java.lang.reflect.Field> all = new java.util.ArrayList<>();
for (Class<?> k = c; k != null; k = k.getSuperclass()) all.addAll(java.util.Arrays.asList(k.getDeclaredFields()));
boolean exists = all.stream().anyMatch(f -> f.getName().equals(fieldName));

Type guard

static boolean fieldExists(Class<?> c, String name) {
    for (Class<?> k = c; k != null; k = k.getSuperclass())
        for (java.lang.reflect.Field f : k.getDeclaredFields())
            if (f.getName().equals(name)) return true;
    return false;
}

Try / catch

try { Field f = FieldUtils.findField(c, name); }
catch (IllegalStateException e) { /* name wrong or obfuscated; verify against source */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/bd539588482fc1b4. Report an issue: GitHub.