{"record":{"id":"59bd75050ba9bcfb","repo":"Tencent/matrix","slug":"method-methodname-is-not-exists","errorCode":null,"errorMessage":"Method <methodName> is not exists.","messagePattern":"Method <methodName> is not exists\\.","errorType":"exception","errorClass":"NoSuchFieldException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectMethod.java","lineNumber":53,"sourceCode":"                break;\n            } catch (Exception e) {\n            }\n            clazz = clazz.getSuperclass();\n        }\n        mInit = true;\n    }\n\n    public synchronized <T> T invoke(Object instance, Object... args) throws NoSuchFieldException, IllegalAccessException,\n            IllegalArgumentException, InvocationTargetException {\n        return invoke(instance, false, args);\n    }\n\n    public synchronized <T> T invoke(Object instance, boolean ignoreFieldNoExist, Object... args)\n            throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {\n        prepare();\n        if (mMethod == null) {\n            if (!ignoreFieldNoExist) {\n                throw new NoSuchFieldException(\"Method \" + mMethodName + \" is not exists.\");\n            }\n            MatrixLog.w(TAG, \"Field %s is no exists\", mMethodName);\n            return null;\n        }\n        return (T) mMethod.invoke(instance, args);\n    }\n\n\n    public synchronized <T> T invokeWithoutThrow(Object instance, Object... args) {\n        try {\n            return invoke(instance, true, args);\n        } catch (NoSuchFieldException e) {\n            MatrixLog.e(TAG, \"invokeWithoutThrow, exception occur :%s\", e);\n        } catch (IllegalAccessException e) {\n            MatrixLog.e(TAG, \"invokeWithoutThrow, exception occur :%s\", e);\n        } catch (IllegalArgumentException e) {\n            MatrixLog.e(TAG, \"invokeWithoutThrow, exception occur :%s\", e);\n        } catch (InvocationTargetException e) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectMethod.java#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Verify the method name and exact parameter types against the target class/SDK version (use clazz.getDeclaredMethod to inspect).","Call invoke(instance, true, args...) to tolerate a missing method and get null back instead of a throw, when the method is optional.","Check ProGuard/R8 keep rules so the target method is not renamed in release builds.","Guard by SDK version: only attempt the reflective call on API levels where the method exists."],"exampleFix":"// before\nObject result = new ReflectMethod(clazz, \"getRunningTasks\", int.class).invoke(activityManager, false, 1);\n// after\nObject result = new ReflectMethod(clazz, \"getRunningTasks\", int.class).invoke(activityManager, true, 1);\nif (result == null) {\n    MatrixLog.w(TAG, \"getRunningTasks not available on this API level\");\n}","handlingStrategy":"try-catch","validationCode":"try {\n    clazz.getDeclaredMethod(methodName, paramTypes);\n} catch (NoSuchMethodException e) {\n    MatrixLog.w(TAG, \"method %s not present, skipping hook\", methodName);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    T result = reflectMethod.invoke(instance, false, args);\n} catch (NoSuchFieldException | NoSuchMethodException e) {\n    MatrixLog.w(TAG, \"method %s missing on this API level\", e.getMessage());\n} catch (InvocationTargetException e) {\n    Throwable cause = e.getTargetException();\n    MatrixLog.e(TAG, \"invocation failed\", cause);\n}","preventionTips":["Pass ignoreFieldNoExist=true for optional methods that may not exist on all API levels.","Verify exact parameter types (primitives vs boxed) before invoking.","Check ProGuard/R8 keep rules for reflectively accessed methods.","Gate reflective hooks by Build.VERSION.SDK_INT."],"tags":["reflection","android","method-not-found","nosuchmethod"],"backgroundTag":"method-not-implemented","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}