{"record":{"id":"b36626169ece92ff","repo":"flowable/flowable-engine","slug":"task-taskid-doesn-t-exist-b36626","errorCode":null,"errorMessage":"task \" + taskId + \" doesn't exist","messagePattern":"task \" \\+ taskId \\+ \" doesn't exist","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/HasTaskVariableCmd.java","lineNumber":56,"sourceCode":"        this.taskId = taskId;\n        this.variableName = variableName;\n        this.isLocal = isLocal;\n    }\n\n    @Override\n    public Boolean execute(CommandContext commandContext) {\n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"taskId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variableName is null\");\n        }\n\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskEntity task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n\n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"task \" + taskId + \" doesn't exist\", Task.class);\n        }\n        boolean hasVariable = false;\n\n        if (isLocal) {\n            hasVariable = task.hasVariableLocal(variableName);\n        } else {\n            hasVariable = task.hasVariable(variableName);\n        }\n\n        return hasVariable;\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":69,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/HasTaskVariableCmd.java#L38-L69","documentation":"HasTaskVariableCmd.execute() looks up the task by id via the task service; when no TaskEntity exists for the given taskId it throws FlowableObjectNotFoundException ('task <id> doesn't exist'). This means the id is well-formed but references a task that is not in the database.","triggerScenarios":"Calling taskService.hasVariable/hasVariableLocal with a taskId that was deleted, belongs to another database/schema, or was never created (e.g. the task was completed and removed earlier).","commonSituations":"Stale task ids held in UI state or cached forms after task completion; environment mismatch (test DB vs prod DB); multi-tenant setups where the id comes from a different tenant's data; history cleanup removing tasks before dependent logic runs.","solutions":["Verify the task exists first with taskService.createTaskQuery().taskId(id).count() > 0, or use hasVariable on a re-fetched TaskInfo.","Re-check where the taskId is sourced from; refresh it from a fresh task query if it is stale.","Confirm the engine points at the correct database and tenant for this task id.","Catch FlowableObjectNotFoundException and return false / re-query instead of failing the request."],"exampleFix":"// before\nboolean has = taskService.hasVariable(taskId, \"approved\");\n// after\nif (taskService.createTaskQuery().taskId(taskId).count() == 0) {\n    throw new IllegalStateException(\"Task no longer exists: \" + taskId);\n}\nboolean has = taskService.hasVariable(taskId, \"approved\");","handlingStrategy":"try-catch","validationCode":"boolean taskExists = taskService.createTaskQuery().taskId(taskId).count() > 0;\nif (!taskExists) {\n    throw new IllegalStateException(\"Task not found: \" + taskId);\n}","typeGuard":"boolean taskExists(String taskId) {\n    return taskId != null && taskService.createTaskQuery().taskId(taskId).count() > 0;\n}","tryCatchPattern":"try {\n    return taskService.hasVariable(taskId, variableName);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Task {} no longer exists; treating as no-variable\", taskId);\n    return false;\n}","preventionTips":["Re-fetch tasks rather than caching task ids across transactions","Account for history cleanup deleting completed tasks","In multi-tenant setups, verify tenant before using foreign task ids"],"tags":["flowable","task-not-found","stale-reference"],"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-18T16:30:33.424Z"}