{"record":{"id":"83db54b638b829e9","repo":"flowable/flowable-engine","slug":"cannot-use-taskid-together-with-excludetaskvariabl-83db54","errorCode":null,"errorMessage":"Cannot use taskId together with excludeTaskVariables","messagePattern":"Cannot use taskId together with excludeTaskVariables","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java","lineNumber":124,"sourceCode":"        if (excludeLocalVariables) {\n            throw new FlowableIllegalArgumentException(\"Cannot use executionIds together with excludeLocalVariables\");\n        }\n        this.executionIds = executionIds;\n        return this;\n    }\n\n    public VariableInstanceQuery activityInstanceId(String activityInstanceId) {\n        this.activityInstanceId = activityInstanceId;\n        return this;\n    }\n\n    @Override\n    public VariableInstanceQuery taskId(String taskId) {\n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"taskId is null\");\n        }\n        if (excludeTaskRelated) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\n        }\n        if (excludeLocalVariables) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskIds together with excludeLocalVariables\");\n        }\n        this.taskId = taskId;\n        return this;\n    }\n\n    @Override\n    public VariableInstanceQueryImpl taskIds(Set<String> taskIds) {\n        if (taskIds == null) {\n            throw new FlowableIllegalArgumentException(\"taskIds is null\");\n        }\n        if (taskIds.isEmpty()) {\n            throw new FlowableIllegalArgumentException(\"Set of taskIds is empty\");\n        }\n        if (excludeTaskRelated) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskIds together with excludeTaskVariables\");","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java#L106-L142","documentation":"excludeTaskRelated is a flag that excludes variables directly related to a task. Setting it together with a taskId filter is contradictory — you cannot both target a specific task's variables and exclude task-related ones — so Flowable throws FlowableIllegalArgumentException at query-build time.","triggerScenarios":"Calling variableInstanceQuery.excludeTaskVariables() (which sets excludeTaskRelated) and then taskId(id), or taskId first then the exclusion flag.","commonSituations":"Copy-pasted query configuration where the exclusion flag was left from a process/execution-scoped query and then a task filter was added.","solutions":["Remove excludeTaskVariables() from the query that uses taskId()","Build a separate query without the exclusion flag for task-scoped lookups","If the goal is non-task variables, drop the taskId filter entirely"],"exampleFix":"// before\nquery.excludeTaskVariables().taskId(taskId);\n// after\nquery.taskId(taskId);","handlingStrategy":"validation","validationCode":"if (excludeTaskRelated && taskId != null) {\n    throw new IllegalArgumentException(\"excludeTaskVariables cannot be combined with taskId\");\n}","typeGuard":"boolean isTaskScopedQuery(VariableInstanceQuery q) { return q != null; } // enforce flag exclusivity at call site","tryCatchPattern":"try {\n    query.taskId(taskId);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"excludeTaskVariables\")) {\n        query = createBaseQuery().taskId(taskId);\n    } else { throw e; }\n}","preventionTips":["Do not set excludeTaskVariables on queries targeting a specific task","Review copied query templates for leftover exclusion flags","Add integration tests for every flag+filter combination you rely on"],"tags":["flowable","query-validation","mutually-exclusive","variable-instance-query"],"backgroundTag":"mutually-exclusive-options","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"}