{"record":{"id":"d5736fc66760c541","repo":"flowable/flowable-engine","slug":"task-taskid-doesn-t-exist-d5736f","errorCode":null,"errorMessage":"task \" + taskId + \" doesn't exist","messagePattern":"task \" \\+ taskId \\+ \" doesn't exist","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/HasTaskVariableCmd.java","lineNumber":55,"sourceCode":"        this.variableName = variableName;\n        this.isLocal = isLocal;\n    }\n\n    @Override\n    public Boolean execute(CommandContext commandContext) {\n        if (taskId == null) {\n            throw new ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n        if (variableName == null) {\n            throw new ActivitiIllegalArgumentException(\"variableName is null\");\n        }\n\n        TaskEntity task = commandContext\n                .getTaskEntityManager()\n                .findTaskById(taskId);\n\n        if (task == null) {\n            throw new ActivitiObjectNotFoundException(\"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":37,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/HasTaskVariableCmd.java#L37-L68","documentation":"Lookup failure in flowable5 HasTaskVariableCmd.execute: both taskId and variableName passed validation, but no task entity exists with that id, so the variable-existence check cannot be performed.","triggerScenarios":"taskService.hasVariable(taskId, name) on a task that was completed and deleted, or with an invalid taskId; tasks can be removed when their process instance ends or the task is completed.","commonSituations":"Checking a variable on a task after it was completed in the meantime; stale task ids stored in a UI or external table; concurrent completion racing the variable check.","solutions":["Check task existence first via taskService.createTaskQuery().taskId(id).singleResult()","Catch ActivitiObjectNotFoundException and treat as 'task already completed'","Fix stale id sources (e.g. re-query task state instead of caching ids across transactions)"],"exampleFix":"// before\nboolean has = taskService.hasVariable(taskId, name);\n// after\nTask t = taskService.createTaskQuery().taskId(taskId).singleResult();\nboolean has = t != null && taskService.hasVariable(taskId, name);","handlingStrategy":"validation","validationCode":"boolean exists = taskService.createTaskQuery().taskId(taskId).count() > 0;","typeGuard":null,"tryCatchPattern":"try { return taskService.hasVariable(taskId, name); } catch (ActivitiObjectNotFoundException e) { log.warn(\"task {} already completed\", taskId); return false; }","preventionTips":["Re-query task state instead of caching task ids across transactions","Expect completion races in concurrent UI/service flows","Scope variable checks to live tasks only"],"tags":["java","activiti","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-18T11:17:12.947Z"}