Tencent/tinker · error · NoSuchMethodException
Constructor with parameters {} not found in {}
Error message
Constructor with parameters {} not found in {} What it means
ShareReflectUtil.findConstructor(Object instance, Class<?>... parameterTypes) walks the instance's class hierarchy calling getDeclaredConstructor and throws NoSuchMethodException('Constructor with parameters [<types>] not found in <instance.getClass()>') when no matching constructor exists. As with methods, the parameter match is exact — no boxing conversions or superclass parameters are accepted.
Source
Thrown at tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareReflectUtil.java:164
* @throws NoSuchMethodException if the constructor cannot be located
*/
public static Constructor<?> findConstructor(Object instance, Class<?>... parameterTypes)
throws NoSuchMethodException {
for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(parameterTypes);
if (!ctor.isAccessible()) {
ctor.setAccessible(true);
}
return ctor;
} catch (NoSuchMethodException e) {
// ignore and search next
}
}
throw new NoSuchMethodException("Constructor"
+ " with parameters "
+ Arrays.asList(parameterTypes)
+ " not found in " + instance.getClass());
}
/**
* Replace the value of a field containing a non null array, by a new array containing the
* elements of the original array plus the elements of extraElements.
*
* @param instance the instance whose field is to be modified.
* @param fieldName the field to modify.
* @param extraElements elements to append at the end of the array.
*/
public static void expandFieldArray(Object instance, String fieldName, Object[] extraElements)
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Field jlrField = findField(instance, fieldName);
Object[] original = (Object[]) jlrField.get(instance);View on GitHub (pinned to 1b7ea02c23)
Solutions
- Enumerate getDeclaredConstructors() for the failing class and pass the exact parameter types observed.
- Version-gate the constructor lookup and try known variants per API level.
- Verify the instance passed is of the type you think (message prints instance.getClass()).
- Keep tinker updated for maintained constructor compatibility.
Example fix
// before
Constructor<?> c = ShareReflectUtil.findConstructor(app, Context.class); // ctor may be (Context, String)
// after
for (Constructor<?> cand : app.getClass().getDeclaredConstructors()) {
ShareTinkerLog.i(TAG, "ctor params: " + Arrays.toString(cand.getParameterTypes()));
}
Constructor<?> c = ShareReflectUtil.findConstructor(app, Context.class, String.class); Defensive patterns
Strategy: validation
Validate before calling
static boolean hasCtor(Class<?> c, Class<?>... p) {
try { c.getDeclaredConstructor(p); return true; }
catch (NoSuchMethodException e) { return false; }
} Try / catch
catch NoSuchMethodException -> enumerate getDeclaredConstructors and pick by parameter-count/assignability instead of exact match
Prevention
- Pass exact declared parameter types; getDeclaredConstructor does no widening.
- Print instance.getClass() on failure — the message tells you where the search actually started.
- Version-gate constructor reflection on framework classes.
When it happens
Trigger: Requesting a constructor with parameter types that do not exactly match any declared constructor on the instance's class or its superclasses (e.g. (Context) when the ctor takes (Context, String)); instantiating framework classes whose ctor changed; instance being a subclass so the search starts lower than expected.
Common situations: Hidden framework constructors changing arity across Android versions; obfuscated classes with changed ctor signatures; generic factory code passing the wrong Class tokens.
Related errors
- Field {} not found in {}
- Method {} with parameters {} not found in {}
- file is null.
- name == null
- createDelegate failed
AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14).
Data as JSON: /api/errors/34a71b84f359f31e.
Report an issue: GitHub.