{"record":{"id":"92c1252d35c0f3b6","repo":"flowable/flowable-engine","slug":"cannot-find-task-with-id-taskid-92c125","errorCode":null,"errorMessage":"Cannot find task with id \" + taskId","messagePattern":"Cannot find task with id \" \\+ taskId","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/NeedsActiveTaskCmd.java","lineNumber":52,"sourceCode":"    protected String taskId;\n\n    public NeedsActiveTaskCmd(String taskId) {\n        this.taskId = taskId;\n    }\n\n    @Override\n    public T execute(CommandContext commandContext) {\n\n        if (taskId == null) {\n            throw new ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n\n        TaskEntity task = commandContext\n                .getTaskEntityManager()\n                .findTaskById(taskId);\n\n        if (task == null) {\n            throw new ActivitiObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n        }\n\n        if (task.isSuspended()) {\n            throw new ActivitiException(getSuspendedTaskException());\n        }\n\n        return execute(commandContext, task);\n    }\n\n    /**\n     * Subclasses must implement in this method their normal command logic. The provided task is ensured to be active.\n     */\n    protected abstract T execute(CommandContext commandContext, TaskEntity task);\n\n    /**\n     * Subclasses can override this method to provide a customized exception message that will be thrown when the task is suspended.\n     */\n    protected String getSuspendedTaskException() {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/NeedsActiveTaskCmd.java#L34-L70","documentation":"Thrown when the taskId is non-null but no task entity with that id exists; ActivitiObjectNotFoundException is raised with the expected Task.class. The task may have been completed or deleted, or the id belongs to a different engine/database.","triggerScenarios":"Calling taskService.complete/claim/setAssignee/etc. with an id of a task that was already completed, deleted by another user, never existed in this database, or comes from a stale form/UI payload.","commonSituations":"Double-submit: two users or retries complete the same task and the second call fails; long-lived UI sessions holding task ids after a DB cleanup; connecting to the wrong datasource or cluster.","solutions":["Check existence first via taskService.createTaskQuery().taskId(id).singleResult() and handle the not-found case gracefully in the UI.","Treat the task as already processed on ObjectNotFoundException (idempotent handling) rather than retrying blindly.","Verify engine/datasource configuration so the call hits the database that actually owns the task.","Refresh the task list instead of reusing cached ids from an old page render."],"exampleFix":"// before\ntaskService.complete(taskId);\n\n// after\nTask task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task != null) {\n    taskService.complete(taskId);\n} else {\n    logger.info(\"Task {} already completed or deleted\", taskId);\n}","handlingStrategy":"validation","validationCode":"Task task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task == null) throw new IllegalStateException(\"task not found: \" + taskId);","typeGuard":null,"tryCatchPattern":"try {\n    taskService.complete(taskId);\n} catch (ActivitiObjectNotFoundException e) {\n    // idempotent: task already completed or deleted\n}","preventionTips":["Handle double-submits idempotently instead of treating not-found as fatal","Refresh task lists in UIs instead of reusing stale ids","Verify all nodes point at the same engine database"],"tags":["activiti","flowable","task-not-found","runtime"],"backgroundTag":"entity-not-found","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"}