{"record":{"id":"4b84728271f33549","repo":"flowable/flowable-engine","slug":"error-while-completing-task","errorCode":null,"errorMessage":"Error while completing task: ","messagePattern":"Error while completing task: ","errorType":"exception","errorClass":"FlowableCdiException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/annotation/CompleteTaskInterceptor.java","lineNumber":52,"sourceCode":"public class CompleteTaskInterceptor implements Serializable {\r\n\r\n    private static final long serialVersionUID = 1L;\r\n\r\n    @Inject\r\n    BusinessProcess businessProcess;\r\n\r\n    @AroundInvoke\r\n    public Object invoke(InvocationContext ctx) throws Exception {\r\n        try {\r\n            Object result = ctx.proceed();\r\n\r\n            CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);\r\n            boolean endConversation = completeTaskAnnotation.endConversation();\r\n            businessProcess.completeTask(endConversation);\r\n\r\n            return result;\r\n        } catch (InvocationTargetException e) {\r\n            throw new FlowableCdiException(\"Error while completing task: \" + e.getCause().getMessage(), e.getCause());\r\n        }\r\n    }\r\n\r\n}\r\n","sourceCodeStart":34,"sourceCodeEnd":57,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/annotation/CompleteTaskInterceptor.java#L34-L57","documentation":"CompleteTaskInterceptor wraps methods annotated with @CompleteTask; after the intercepted method runs it completes the associated task via BusinessProcess.completeTask(). If completing the task throws any checked exception (wrapped by CDI in InvocationTargetException), the interceptor rethrows it as FlowableCdiException with the cause's message prefixed by 'Error while completing task: '.","triggerScenarios":"A @CompleteTask-annotated business method finishes and BusinessProcess.completeTask(endConversation) fails — e.g. the task was already completed or deleted, the associated execution ended, or the engine throws while flushing variable changes; the original exception's getMessage() is null so the message ends with just the prefix.","commonSituations":"Concurrent completion of the same task (user double-submits a form), task completed earlier in the same transaction, missing or inactive CDI context so no task is associated, or optimistic-locking exceptions from concurrent process updates.","solutions":["Inspect e.getCause() (the wrapped FlowableException) to find the real failure; the outer message is only a prefix.","Guard against double completion: check taskService.createTaskQuery().taskId(id).singleResult() != null, or catch and treat FlowableTaskAlreadyClaimed/TaskNotFoundException as idempotent.","Ensure an active CDI conversation/scope with an associated task (BusinessProcess.associateTask(task)) before invoking the annotated method."],"exampleFix":"// before\n@CompleteTask\npublic void finish() { ... } // task may already be completed\n// after\n@CompleteTask\npublic void finish() {\n    if (taskService.createTaskQuery().taskId(taskId).singleResult() == null) return;\n    ...\n}","handlingStrategy":"try-catch","validationCode":"Task t = taskService.createTaskQuery().taskId(taskId).singleResult();\nboolean completable = t != null;","typeGuard":"null","tryCatchPattern":"try { businessProcess.completeTask(true); } catch (FlowableCdiException e) { log.error(\"complete failed\", e.getCause()); if (!isTaskStillOpen(taskId)) { /* treat as idempotent success */ } }","preventionTips":["Check task existence before @CompleteTask methods run","Design completion flows to be idempotent against double submission","Always log e.getCause(), not just the outer message"],"tags":["cdi","task-completion","wrapper-exception"],"backgroundTag":"invalid-state-transition","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"}