{"record":{"id":"f33aa8b4613cb016","repo":"flowable/flowable-engine","slug":"couldn-t-invoke-methodname-on-target-f33aa8","errorCode":null,"errorMessage":"couldn't invoke ${methodName} on ${target}","messagePattern":"couldn't invoke (.+?) on (.+?)","errorType":"exception","errorClass":"org.activiti.engine.ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java","lineNumber":147,"sourceCode":"    }\n\n    public static Object instantiate(String className) {\n        try {\n            Class<?> clazz = loadClass(className);\n            return clazz.newInstance();\n        } catch (Exception e) {\n            throw new ActivitiException(\"couldn't instantiate class \" + className, e);\n        }\n    }\n\n    public static Object invoke(Object target, String methodName, Object[] args) {\n        try {\n            Class<? extends Object> clazz = target.getClass();\n            Method method = findMethod(clazz, methodName, args);\n            method.setAccessible(true);\n            return method.invoke(target, args);\n        } catch (Exception e) {\n            throw new ActivitiException(\"couldn't invoke \" + methodName + \" on \" + target, e);\n        }\n    }\n\n    /**\n     * Returns the field of the given object or null if it doesnt exist.\n     */\n    public static Field getField(String fieldName, Object object) {\n        return getField(fieldName, object.getClass());\n    }\n\n    /**\n     * Returns the field of the given class or null if it doesnt exist.\n     */\n    public static Field getField(String fieldName, Class<?> clazz) {\n        Field field = null;\n        try {\n            field = clazz.getDeclaredField(fieldName);\n        } catch (SecurityException e) {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java#L129-L165","documentation":"ReflectUtil.invoke() wraps any Exception raised while reflectively locating and calling a method via method.invoke(). The ActivitiException names the method and target object and chains the underlying cause (typically NoSuchMethodException from findMethod, or IllegalArgumentException/InvocationTargetException from the call itself). It is thrown because the engine cannot report reflection failures without knowing the method name and receiver.","triggerScenarios":"ReflectUtil.invoke(target, methodName, args) is called when the target class has no matching declared method, the method is not accessible, or the method itself throws; args do not match parameters (findMethod has no parameter matching).","commonSituations":"Calling an internal hook/callback method whose signature changed between engine versions; passing wrong argument count/types; invoking methods on proxy or restricted classes where setAccessible fails under a SecurityManager or JPMS module restrictions.","solutions":["Check the chained cause exception for the real reflection failure","Verify the method name spelling and that it exists on the target's class (use findMethod/BeanUtils semantics)","Ensure the args array matches the method's parameter types exactly","If running under strong encapsulation (Java 9+), add the necessary --add-opens flags or avoid reflective invocation"],"exampleFix":"// before\nObject result = ReflectUtil.invoke(processInstance, \"getProcessDefinicion\", null); // typo, wrong name\n// after\nObject result = ReflectUtil.invoke(processInstance, \"getProcessDefinition\", null);","handlingStrategy":"try-catch","validationCode":"// before invoking\nMethod m = target.getClass().getMethod(methodName);\nif (m == null) throw new IllegalStateException(\"method \" + methodName + \" missing on \" + target.getClass());","typeGuard":"boolean canInvoke(Object target, String name) {\n  try { target.getClass().getDeclaredMethod(name); return true; }\n  catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n  Object r = ReflectUtil.invoke(target, methodName, args);\n} catch (ActivitiException e) {\n  logger.error(\"reflective invoke failed for \" + methodName + \" on \" + target, e.getCause());\n  // fallback path\n}","preventionTips":["Prefer direct typed calls over reflection when possible","Verify method names/signatures after upgrading engine versions","Keep args arrays aligned with parameter types","Watch for JPMS/SecurityManager restrictions in logs"],"tags":["reflection","java","engine"],"backgroundTag":"method-not-implemented","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}