{"record":{"id":"82bab2110adf4f1f","repo":"flowable/flowable-engine","slug":"cannot-use-taskids-together-with-excludetaskvariab-82bab2","errorCode":null,"errorMessage":"Cannot use taskIds together with excludeTaskVariables","messagePattern":"Cannot use taskIds 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":142,"sourceCode":"            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\");\n        }\n        if (excludeLocalVariables) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskIds together with excludeLocalVariables\");\n        }\n        this.taskIds = taskIds;\n        return this;\n    }\n\n    @Override\n    public VariableInstanceQuery excludeTaskVariables() {\n        if (taskId != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\n        }\n        if (taskIds != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskIds together with excludeTaskVariables\");\n        }\n        excludeTaskRelated = true;\n        return this;","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java#L124-L160","documentation":"taskIds(Set<String>) cannot be combined with excludeTaskVariables (excludeTaskRelated). Excluding task-related variables while filtering by a specific set of tasks is contradictory, so Flowable throws FlowableIllegalArgumentException at query-build time.","triggerScenarios":"Calling variableInstanceQuery.excludeTaskVariables().taskIds(ids) in either order.","commonSituations":"A generic query factory that conditionally appends excludeTaskVariables for 'non-task variable' reports, accidentally applied to a task-id-based lookup.","solutions":["Remove excludeTaskVariables() when using taskIds()","Split query construction into task-scoped (taskIds, no exclusion) and non-task paths","Handle the exclusion via post-processing of results instead"],"exampleFix":"// before\nquery.excludeTaskVariables().taskIds(taskIds);\n// after\nquery.taskIds(taskIds);","handlingStrategy":"validation","validationCode":"if (excludeTaskRelated && taskIds != null) {\n    throw new IllegalArgumentException(\"excludeTaskVariables cannot be combined with taskIds\");\n}","typeGuard":"boolean isTaskCollectionQuery(VariableInstanceQuery q) { return q != null; } // enforce flag exclusivity at call site","tryCatchPattern":"try {\n    query.taskIds(taskIds);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"excludeTaskVariables\")) {\n        query = createBaseQuery().taskIds(taskIds);\n    } else { throw e; }\n}","preventionTips":["Never combine excludeTaskVariables with taskIds()/taskId()","Encapsulate flag+filter exclusivity rules in one query-builder utility","Add tests for all exclusion-flag combinations against task filters"],"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"}