{"record":{"id":"aa553995f9843fb3","repo":"flowable/flowable-engine","slug":"cannot-find-task-with-id","errorCode":null,"errorMessage":"Cannot find task with id ","messagePattern":"Cannot find task with id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/NeedsActiveTaskCmd.java","lineNumber":53,"sourceCode":"\n    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 FlowableIllegalArgumentException(\"taskId is null\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        TaskEntity task = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n\n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n        }\n\n        if (task.isSuspended()) {\n            throw new FlowableException(getSuspendedTaskExceptionPrefix() + \" a suspended \" + task);\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 getSuspendedTaskExceptionPrefix() {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/NeedsActiveTaskCmd.java#L35-L71","documentation":"After the null check, NeedsActiveTaskCmd.execute() looks up the task via the task service. If no task exists with the given id it throws FlowableObjectNotFoundException 'Cannot find task with id <taskId>' with Task.class as the type, indicating the referenced task entity does not exist (or is not visible) in the persistent store.","triggerScenarios":"Executing a task command with an id that was never persisted, was deleted (e.g. cascading delete after case instance termination), or belongs to a different database/tenant scope.","commonSituations":"Stale task ids cached from a previous run; task deleted by another user/process concurrently; id copied from the BPMN engine (process tasks) while operating on the CMMN engine; test/prod data mixing.","solutions":["Verify the task exists first: taskService.createTaskQuery().taskId(id).singleResult() != null","Use freshly fetched task ids from taskService.createTaskQuery() results instead of cached values","Catch FlowableObjectNotFoundException to handle missing tasks gracefully"],"exampleFix":"// before\ntaskService.complete(oldTaskId); // task already deleted\n// after\nTask task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task != null) { taskService.complete(task.getId()); }","handlingStrategy":"validation","validationCode":"Task t = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (t == null) throw new IllegalArgumentException(\"No such task: \" + taskId);","typeGuard":null,"tryCatchPattern":"try { taskService.complete(taskId); } catch (FlowableObjectNotFoundException e) { log.warn(\"Task {} no longer exists\", taskId); }","preventionTips":["Refresh task references before acting (tasks can be deleted concurrently)","Don't persist task ids across transactions/restarts; re-query instead","Verify you're on the same engine/datasource that owns the task"],"tags":["flowable","cmmn","entity-not-found","task"],"backgroundTag":"record-not-found","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"}