{"record":{"id":"6a894598d9c8f8d8","repo":"flowable/flowable-engine","slug":"task-taskid-doesn-t-exist-6a8945","errorCode":null,"errorMessage":"task ${taskId} doesn't exist","messagePattern":"task (.+?) doesn't exist","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasTaskVariableCmd.java","lineNumber":57,"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        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        TaskEntity task = cmmnEngineConfiguration.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":39,"sourceCodeEnd":70,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasTaskVariableCmd.java#L39-L70","documentation":"HasTaskVariableCmd.execute throws FlowableObjectNotFoundException when the taskId is non-null but no matching task exists in the task service. The engine fetches the task via the task service before evaluating variables; a null result means the variable question cannot be answered for a nonexistent task.","triggerScenarios":"Calling hasVariable with a task id of a completed/deleted task, a typo'd id, or an id belonging to another engine/database.","commonSituations":"Working with historic tasks (query runtime task service instead of history), stale ids cached in the application, hard-coded test ids, or cross-environment database confusion.","solutions":["Check task existence first via taskService.createTaskQuery().taskId(id).singleResult()","For completed tasks use the history service task query/variables APIs","Verify the id source and that you target the correct database/schema"],"exampleFix":"// before\nboolean has = taskService.hasVariable(taskId, \"approved\");\n// after\nTask task = taskService.createTaskQuery().taskId(taskId).singleResult();\nboolean has = task != null && taskService.hasVariable(taskId, \"approved\");","handlingStrategy":"try-catch","validationCode":"Task task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task == null) {\n    // task completed/deleted; fall back to history\n}","typeGuard":"boolean taskExists(TaskService ts, String id) {\n    return id != null && ts.createTaskQuery().taskId(id).singleResult() != null;\n}","tryCatchPattern":"try {\n    return taskService.hasVariable(taskId, variableName);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Task {} not found; checking history\", taskId);\n    return historyService.createHistoricVariableInstanceQuery()\n        .taskId(taskId).variableName(variableName).count() > 0;\n}","preventionTips":["Use history APIs for completed tasks rather than runtime task service","Re-resolve task ids instead of caching them long-term","Ensure all nodes point to the same database/schema"],"tags":["flowable","cmmn","not-found","task"],"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-14T05:17:10.506Z"}