{"record":{"id":"23d3107527e4cdc5","repo":"flowable/flowable-engine","slug":"cannot-use-taskids-together-with-excludetaskvariab","errorCode":null,"errorMessage":"Cannot use taskIds together with excludeTaskVariables","messagePattern":"Cannot use taskIds together with excludeTaskVariables","errorType":"validation","errorClass":"org.flowable.common.engine.api.FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/HistoricVariableInstanceQueryImpl.java","lineNumber":154,"sourceCode":"            throw new FlowableIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\n        }\n        if (excludeLocalVariables) {\n            throw new FlowableIllegalArgumentException(\"Cannot use taskId together with excludeLocalVariables\");\n        }\n        this.taskId = taskId;\n        return this;\n    }\n\n    @Override\n    public HistoricVariableInstanceQueryImpl 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 HistoricVariableInstanceQuery 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":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/HistoricVariableInstanceQueryImpl.java#L136-L172","documentation":"HistoricVariableInstanceQueryImpl.taskIds() throws FlowableIllegalArgumentException when excludeTaskVariables (excludeTaskRelated) has already been enabled. Filtering by a set of task ids while excluding task-related variables is contradictory and rejected at query-configuration time.","triggerScenarios":"Calling query.taskIds(set) after query.excludeTaskVariables()/excludeTaskRelated(true) on the same query instance.","commonSituations":"Request-driven builder code that applies the exclusion flag from one query param and task-id filters from another; reused query objects.","solutions":["Remove excludeTaskVariables() when filtering by task ids","Apply taskIds(...) before enabling exclusion, or skip exclusion when task ids are present","Instantiate a fresh query per request to avoid pre-enabled exclusion flags"],"exampleFix":"// before\nquery.excludeTaskVariables();\nquery.taskIds(taskIds); // throws\n// after\nquery.taskIds(taskIds); // do not call excludeTaskVariables()","handlingStrategy":"validation","validationCode":"boolean excludeTaskRelated = /* your exclude flag */;\nif (excludeTaskRelated && taskIds != null && !taskIds.isEmpty()) {\n    throw new IllegalStateException(\"taskIds and excludeTaskVariables are mutually exclusive\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    query.taskIds(taskIds);\n} catch (FlowableIllegalArgumentException e) {\n    // handle conflicting query options\n}","preventionTips":["Never combine taskIds with excludeTaskVariables/excludeTaskRelated","Skip exclusion flags whenever task-id filters are supplied","Build queries through one helper that validates option combinations"],"tags":[],"backgroundTag":null,"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"}