Tencent/matrix · error · IllegalArgumentException

Both of invoker and fieldName can not be null or nil.

Error message

Both of invoker and fieldName can not be null or nil.

What it means

The ReflectFiled constructor throws IllegalArgumentException when the target Class is null or the fieldName is null/empty. ReflectFiled lazily resolves a field by name, so both a class and a non-empty field name are mandatory inputs.

Solutions

  1. Pass a concrete Class object and a non-empty field name to the constructor
  2. Validate inputs before constructing ReflectFiled
  3. If the name comes from config, check for null/empty and fall back to a default
  4. Ensure obfuscation (ProGuard/R8) keep rules preserve the target class and field

Example fix

// before
ReflectFiled f = new ReflectFiled(getFieldClass(), getConfigName()); // may throw

// after
Class<?> clazz = getFieldClass();
String name = getConfigName();
if (clazz != null && name != null && !name.isEmpty()) {
    ReflectFiled f = new ReflectFiled(clazz, name);
}
Defensive patterns

Strategy: validation

Validate before calling

if (clazz == null || fieldName == null || fieldName.isEmpty()) {
    throw new IllegalArgumentException("clazz and fieldName are required");
}
ReflectFiled f = new ReflectFiled(clazz, fieldName);

Type guard

boolean valid = (clazz != null && fieldName != null && !fieldName.isEmpty());

Try / catch

try {
    ReflectFiled f = new ReflectFiled(clazz, fieldName);
} catch (IllegalArgumentException e) {
    Log.w(TAG, "invalid reflect args", e);
}

Prevention

When it happens

Trigger: new ReflectFiled(null, "field"), new ReflectFiled(Foo.class, null), or new ReflectFiled(Foo.class, "") — any construction with missing class or name.

Common situations: Field names supplied from configuration or constants that are null/empty at runtime; class references lost after refactoring or proguard changes; building reflective helpers from dynamic input.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/0106f11795710403. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectFiled.java:17

package com.tencent.matrix.util;



import java.lang.reflect.Field;

public class ReflectFiled<Type> {
    private static final String TAG = "ReflectFiled";
    private Class<?> mClazz;
    private String mFieldName;

    private boolean mInit;
    private Field mField;

    public ReflectFiled(Class<?> clazz, String fieldName) {
        if (clazz == null || fieldName == null || fieldName.length() == 0) {
            throw new IllegalArgumentException("Both of invoker and fieldName can not be null or nil.");
        }
        this.mClazz = clazz;
        this.mFieldName = fieldName;
    }

    private synchronized void prepare() {
        if (mInit) {
            return;
        }
        Class<?> clazz = mClazz;
        while (clazz != null) {
            try {
                Field f = clazz.getDeclaredField(mFieldName);
                f.setAccessible(true);
                mField = f;
                break;
            } catch (Exception e) {
            }

View on GitHub (pinned to 3b8293bd65)