{"record":{"id":"c5643dd8659b941e","repo":"Tencent/tinker","slug":"method-with-parameters-not-found-in","errorCode":null,"errorMessage":"Method {} with parameters {} not found in {}","messagePattern":"Method (.+?) with parameters (.+?) not found in (.+?)","errorType":"exception","errorClass":"NoSuchMethodException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareReflectUtil.java","lineNumber":101,"sourceCode":"     * @throws NoSuchMethodException if the method cannot be located\n     */\n    public static Method findMethod(Object instance, String name, Class<?>... parameterTypes)\n        throws NoSuchMethodException {\n        for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n            try {\n                Method method = clazz.getDeclaredMethod(name, parameterTypes);\n\n                if (!method.isAccessible()) {\n                    method.setAccessible(true);\n                }\n\n                return method;\n            } catch (NoSuchMethodException e) {\n                // ignore and search next\n            }\n        }\n\n        throw new NoSuchMethodException(\"Method \"\n            + name\n            + \" with parameters \"\n            + Arrays.asList(parameterTypes)\n            + \" not found in \" + instance.getClass());\n    }\n\n    /**\n     * Locates a given method anywhere in the class inheritance hierarchy.\n     *\n     * @param clazz          a class to search the method into.\n     * @param name           method name\n     * @param parameterTypes method parameter types\n     * @return a method object\n     * @throws NoSuchMethodException if the method cannot be located\n     */\n    public static Method findMethod(Class<?> clazz, String name, Class<?>... parameterTypes)\n            throws NoSuchMethodException {\n        for (; clazz != null; clazz = clazz.getSuperclass()) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareReflectUtil.java#L83-L119","documentation":"ShareReflectUtil.findMethod(Object instance, String name, Class<?>... parameterTypes) walks the instance's class hierarchy calling getDeclaredMethod; if no class declares a method with that exact name and parameter types it throws NoSuchMethodException('Method <name> with parameters [<types>] not found in <instance.getClass()>'). Parameter-type mismatch is the most common cause: getDeclaredMethod requires an exact signature, not assignment compatibility.","triggerScenarios":"Passing subclass parameter types when the declared method takes superclasses (e.g. asking for (String) when the method declares (Object)); renamed framework methods on specific OEM builds; instance being a subclass whose parent declares the method privately in a different signature.","commonSituations":"Calling framework hidden methods whose signature changed across Android versions; mixing up the instance-based and class-based findMethod overloads; interface default methods not found because getDeclaredMethod does not search interfaces.","solutions":["Match the declared signature exactly — enumerate getDeclaredMethods() and compare, or implement a compatible-signature search.","Gate by API level and use the per-version method name/signature (as tinker's own V14/V19/V23 installers do).","If the method is on an interface, reflect on the interface class instead of the implementing instance.","Upgrade tinker for updated compatibility tables."],"exampleFix":"// before\nMethod m = ShareReflectUtil.findMethod(loader, \"addDexPath\", String.class); // NoSuchMethod if it takes (String, File)\n\n// after\nMethod m = null;\nfor (Method cand : loader.getClass().getDeclaredMethods()) {\n    if (cand.getName().equals(\"addDexPath\")) { m = cand; m.setAccessible(true); break; }\n}\nif (m == null) throw new IllegalStateException(\"addDexPath missing on \" + loader.getClass());","handlingStrategy":"validation","validationCode":"static boolean hasExactMethod(Object o, String n, Class<?>... p) {\n    try { ShareReflectUtil.findMethod(o, n, p); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch NoSuchMethodException -> enumerate getDeclaredMethods and match by name when parameter types differ across versions","preventionTips":["Match parameter types exactly, including primitives (int.class not Integer.class).","Remember getDeclaredMethod does not search interfaces — reflect on the declaring interface instead.","Maintain per-API-level signature tables like tinker's V14/V19/V23 installers."],"tags":["reflection","method-signature","compatibility"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}