{"record":{"id":"1f772d2434b081a4","repo":"flowable/flowable-engine","slug":"exception-while-invoking-tasklistener-s","errorCode":null,"errorMessage":"Exception while invoking TaskListener: %s","messagePattern":"Exception while invoking TaskListener: (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ClassDelegate.java","lineNumber":125,"sourceCode":"        } else if (delegateInstance instanceof JavaDelegate) {\n            return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance, skipExpression);\n        } else {\n            throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + \" doesn't implement \" + ExecutionListener.class + \" nor \" + JavaDelegate.class);\n        }\n    }\n\n    // Task listener\n    @Override\n    public void notify(DelegateTask delegateTask) {\n        if (taskListenerInstance == null) {\n            taskListenerInstance = getTaskListenerInstance();\n        }\n        try {\n            Context.getProcessEngineConfiguration()\n                    .getDelegateInterceptor()\n                    .handleInvocation(new TaskListenerInvocation(taskListenerInstance, delegateTask));\n        } catch (Exception e) {\n            throw new ActivitiException(\"Exception while invoking TaskListener: \" + e.getMessage(), e);\n        }\n    }\n\n    protected TaskListener getTaskListenerInstance() {\n        Object delegateInstance = instantiateDelegate(className, fieldDeclarations);\n        if (delegateInstance instanceof TaskListener) {\n            return (TaskListener) delegateInstance;\n        } else {\n            throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + \" doesn't implement \" + TaskListener.class);\n        }\n    }\n\n    // Activity Behavior\n    @Override\n    public void execute(DelegateExecution execution) {\n        ActivityExecution activityExecution = (ActivityExecution) execution;\n\n        if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ClassDelegate.java#L107-L143","documentation":"ClassDelegate.notify(DelegateTask) invokes the task listener through the configured DelegateInterceptor via TaskListenerInvocation. Any exception thrown inside the interceptor invocation or the listener itself is caught and rethrown as ActivitiException('Exception while invoking TaskListener: ...') with the original as cause.","triggerScenarios":"A task listener event fires (create/assignment/complete) and the delegate's notify() throws, or the DelegateInterceptor.handleInvocation call fails.","commonSituations":"Null pointer inside user listener code; listener accessing missing variables or services; transaction/rollback problems inside the listener.","solutions":["Read the cause stack trace (e.getCause()) to find the real exception in your listener","Fix the bug in the TaskListener implementation","Wrap risky listener logic defensively and handle expected failures inside the listener"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    taskService.complete(taskId);\n} catch (org.activiti.engine.ActivitiException e) {\n    if (e.getMessage().startsWith(\"Exception while invoking TaskListener\")) {\n        Throwable root = ExceptionUtils.getRootCause(e); // inspect the actual listener failure\n    }\n}","preventionTips":["Wrap user listener code with its own try-catch and logging","Test task listeners in isolation before deploying the process","Avoid long-running/unreliable operations inside task listeners"],"tags":["tasklistener","delegate","exception-wrapper"],"backgroundTag":"listener-invocation-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}