{"record":{"id":"e1178f0b50836701","repo":"flowable/flowable-engine","slug":"cannot-use-taskid-together-with-excludelocalvariab-e1178f","errorCode":null,"errorMessage":"Cannot use taskId together with excludeLocalVariables","messagePattern":"Cannot use taskId together with excludeLocalVariables","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java","lineNumber":263,"sourceCode":"    @Override\n    public VariableInstanceQuery subScopeId(String subScopeId) {\n        if (excludeLocalVariables) {\n            throw new FlowableIllegalArgumentException(\"Cannot use subScopeId together with excludeLocalVariables\");\n        }\n        this.subScopeId = subScopeId;\n        return this;\n    }\n    \n    @Override\n    public VariableInstanceQuery scopeType(String scopeType) {\n        this.scopeType = scopeType;\n        return this;\n    }\n\n    @Override\n    public VariableInstanceQuery excludeLocalVariables() {\n        if (taskId != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskId together with excludeLocalVariables\");\n        }\n        if (taskIds != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskIds together with excludeLocalVariables\");\n        }\n        if (executionId != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use executionId together with excludeLocalVariables\");\n        }\n        if (subScopeId != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use subScopeId together with excludeLocalVariables\");\n        }\n        excludeLocalVariables = true;\n        return this;\n    }\n\n    protected void ensureVariablesInitialized() {\n        if (this.queryVariableValue != null) {\n            queryVariableValue.initialize(variableServiceConfiguration);\n        }","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java#L245-L281","documentation":"Flowable throws FlowableIllegalArgumentException when excludeLocalVariables() is called on a query that already has a taskId set. Local task variables are exactly what taskId-scoped queries target, so excluding them is contradictory and the builder rejects the combination eagerly.","triggerScenarios":"Calling query.taskId(\"123\").excludeLocalVariables() (or excludeLocalVariables() after any taskId assignment); helper methods that set a taskId for specificity and then unconditionally exclude local variables.","commonSituations":"Refactors where excludeLocalVariables was added globally to shared query helpers; copying query configuration between execution-based and task-based lookups.","solutions":["Remove excludeLocalVariables() when filtering by taskId","If you need non-local variables only, build the query without taskId and use execution/process-instance scoping instead","Guard the helper so excludeLocalVariables() is only applied when taskId/taskIds/executionId/subScopeId are all unset"],"exampleFix":"// before\nquery.taskId(taskId);\nquery.excludeLocalVariables(); // throws\n// after\nquery.taskId(taskId); // task-local variables kept\n// or for non-local variables only:\nquery.executionId(executionId);\nquery.excludeLocalVariables();","handlingStrategy":"validation","validationCode":"if (taskId != null && excludeLocal) {\n    throw new IllegalArgumentException(\"excludeLocalVariables cannot be used with taskId\");\n}\nquery.taskId(taskId);","typeGuard":null,"tryCatchPattern":"try {\n    query.taskId(taskId).excludeLocalVariables();\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"taskId together with excludeLocalVariables\")) {\n        query = createQuery().taskId(taskId); // drop the exclusion\n    } else {\n        throw e;\n    }\n}","preventionTips":["Do not globally enable excludeLocalVariables in shared query helpers","Document scoping rules (taskId/taskIds/executionId/subScopeId vs local exclusion) in team docs","Prefer explicit per-call-site query construction over copy-pasted chains"],"tags":["query","conflicting-options","validation","flowable"],"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"}