Tencent/tinker · error · NoSuchMethodException

Method {} with parameters {} not found in {}

Error message

Method {} with parameters {} not found in {}

What it means

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.

Source

Thrown at tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareReflectUtil.java:101

     * @throws NoSuchMethodException if the method cannot be located
     */
    public static Method findMethod(Object instance, String name, Class<?>... parameterTypes)
        throws NoSuchMethodException {
        for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
            try {
                Method method = clazz.getDeclaredMethod(name, parameterTypes);

                if (!method.isAccessible()) {
                    method.setAccessible(true);
                }

                return method;
            } catch (NoSuchMethodException e) {
                // ignore and search next
            }
        }

        throw new NoSuchMethodException("Method "
            + name
            + " with parameters "
            + Arrays.asList(parameterTypes)
            + " not found in " + instance.getClass());
    }

    /**
     * Locates a given method anywhere in the class inheritance hierarchy.
     *
     * @param clazz          a class to search the method into.
     * @param name           method name
     * @param parameterTypes method parameter types
     * @return a method object
     * @throws NoSuchMethodException if the method cannot be located
     */
    public static Method findMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
            throws NoSuchMethodException {
        for (; clazz != null; clazz = clazz.getSuperclass()) {

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Match the declared signature exactly — enumerate getDeclaredMethods() and compare, or implement a compatible-signature search.
  2. Gate by API level and use the per-version method name/signature (as tinker's own V14/V19/V23 installers do).
  3. If the method is on an interface, reflect on the interface class instead of the implementing instance.
  4. Upgrade tinker for updated compatibility tables.

Example fix

// before
Method m = ShareReflectUtil.findMethod(loader, "addDexPath", String.class); // NoSuchMethod if it takes (String, File)

// after
Method m = null;
for (Method cand : loader.getClass().getDeclaredMethods()) {
    if (cand.getName().equals("addDexPath")) { m = cand; m.setAccessible(true); break; }
}
if (m == null) throw new IllegalStateException("addDexPath missing on " + loader.getClass());
Defensive patterns

Strategy: validation

Validate before calling

static boolean hasExactMethod(Object o, String n, Class<?>... p) {
    try { ShareReflectUtil.findMethod(o, n, p); return true; }
    catch (NoSuchMethodException e) { return false; }
}

Try / catch

catch NoSuchMethodException -> enumerate getDeclaredMethods and match by name when parameter types differ across versions

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/c5643dd8659b941e. Report an issue: GitHub.