Tencent/matrix · error · NoSuchFieldException

Method is not exists.

Error message

Method <methodName> is not exists.

What it means

ReflectMethod.invoke() first calls prepare() to resolve the underlying java.lang.Method. If resolution failed (the method does not exist on the target class with the given signature) and the ignoreFieldNoExist flag is false, it throws NoSuchFieldException with this message. If ignoreFieldNoExist is true, it only logs a warning and returns null instead, allowing optional-method lookups.

Solutions

  1. Verify the method name and exact parameter types against the target class/SDK version (use clazz.getDeclaredMethod to inspect).
  2. Call invoke(instance, true, args...) to tolerate a missing method and get null back instead of a throw, when the method is optional.
  3. Check ProGuard/R8 keep rules so the target method is not renamed in release builds.
  4. Guard by SDK version: only attempt the reflective call on API levels where the method exists.

Example fix

// before
Object result = new ReflectMethod(clazz, "getRunningTasks", int.class).invoke(activityManager, false, 1);
// after
Object result = new ReflectMethod(clazz, "getRunningTasks", int.class).invoke(activityManager, true, 1);
if (result == null) {
    MatrixLog.w(TAG, "getRunningTasks not available on this API level");
}
Defensive patterns

Strategy: try-catch

Validate before calling

try {
    clazz.getDeclaredMethod(methodName, paramTypes);
} catch (NoSuchMethodException e) {
    MatrixLog.w(TAG, "method %s not present, skipping hook", methodName);
    return;
}

Try / catch

try {
    T result = reflectMethod.invoke(instance, false, args);
} catch (NoSuchFieldException | NoSuchMethodException e) {
    MatrixLog.w(TAG, "method %s missing on this API level", e.getMessage());
} catch (InvocationTargetException e) {
    Throwable cause = e.getTargetException();
    MatrixLog.e(TAG, "invocation failed", cause);
}

Prevention

When it happens

Trigger: Invoking invoke(instance, false, args...) on a ReflectMethod whose method name/signature does not match any declared method of the target class — e.g. after an Android API change removed or renamed the method, or a typo in the method name, or wrong parameterTypes passed to the constructor.

Common situations: Hooking internal/private Android framework methods across OS versions where the method was renamed or removed; obfuscated release builds (ProGuard/R8) renaming the target method; passing parameterTypes that don't exactly match (boxed vs primitive, subclass vs exact type).

Related errors


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

Appendix: source

Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectMethod.java:53

                break;
            } catch (Exception e) {
            }
            clazz = clazz.getSuperclass();
        }
        mInit = true;
    }

    public synchronized <T> T invoke(Object instance, Object... args) throws NoSuchFieldException, IllegalAccessException,
            IllegalArgumentException, InvocationTargetException {
        return invoke(instance, false, args);
    }

    public synchronized <T> T invoke(Object instance, boolean ignoreFieldNoExist, Object... args)
            throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        prepare();
        if (mMethod == null) {
            if (!ignoreFieldNoExist) {
                throw new NoSuchFieldException("Method " + mMethodName + " is not exists.");
            }
            MatrixLog.w(TAG, "Field %s is no exists", mMethodName);
            return null;
        }
        return (T) mMethod.invoke(instance, args);
    }


    public synchronized <T> T invokeWithoutThrow(Object instance, Object... args) {
        try {
            return invoke(instance, true, args);
        } catch (NoSuchFieldException e) {
            MatrixLog.e(TAG, "invokeWithoutThrow, exception occur :%s", e);
        } catch (IllegalAccessException e) {
            MatrixLog.e(TAG, "invokeWithoutThrow, exception occur :%s", e);
        } catch (IllegalArgumentException e) {
            MatrixLog.e(TAG, "invokeWithoutThrow, exception occur :%s", e);
        } catch (InvocationTargetException e) {

View on GitHub (pinned to 3b8293bd65)