{"record":{"id":"34a71b84f359f31e","repo":"Tencent/tinker","slug":"constructor-with-parameters-not-found-in","errorCode":null,"errorMessage":"Constructor with parameters {} not found in {}","messagePattern":"Constructor 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":164,"sourceCode":"     * @throws NoSuchMethodException if the constructor cannot be located\n     */\n    public static Constructor<?> findConstructor(Object instance, Class<?>... parameterTypes)\n            throws NoSuchMethodException {\n        for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n            try {\n                Constructor<?> ctor = clazz.getDeclaredConstructor(parameterTypes);\n\n                if (!ctor.isAccessible()) {\n                    ctor.setAccessible(true);\n                }\n\n                return ctor;\n            } catch (NoSuchMethodException e) {\n                // ignore and search next\n            }\n        }\n\n        throw new NoSuchMethodException(\"Constructor\"\n                + \" with parameters \"\n                + Arrays.asList(parameterTypes)\n                + \" not found in \" + instance.getClass());\n    }\n\n    /**\n     * Replace the value of a field containing a non null array, by a new array containing the\n     * elements of the original array plus the elements of extraElements.\n     *\n     * @param instance      the instance whose field is to be modified.\n     * @param fieldName     the field to modify.\n     * @param extraElements elements to append at the end of the array.\n     */\n    public static void expandFieldArray(Object instance, String fieldName, Object[] extraElements)\n        throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {\n        Field jlrField = findField(instance, fieldName);\n\n        Object[] original = (Object[]) jlrField.get(instance);","sourceCodeStart":146,"sourceCodeEnd":182,"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#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hidden framework constructors changing arity across Android versions; obfuscated classes with changed ctor signatures; generic factory code passing the wrong Class tokens.","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."],"exampleFix":"// before\nConstructor<?> c = ShareReflectUtil.findConstructor(app, Context.class); // ctor may be (Context, String)\n\n// after\nfor (Constructor<?> cand : app.getClass().getDeclaredConstructors()) {\n    ShareTinkerLog.i(TAG, \"ctor params: \" + Arrays.toString(cand.getParameterTypes()));\n}\nConstructor<?> c = ShareReflectUtil.findConstructor(app, Context.class, String.class);","handlingStrategy":"validation","validationCode":"static boolean hasCtor(Class<?> c, Class<?>... p) {\n    try { c.getDeclaredConstructor(p); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch NoSuchMethodException -> enumerate getDeclaredConstructors and pick by parameter-count/assignability instead of exact match","preventionTips":["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."],"tags":["reflection","constructor","compatibility"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}