{"record":{"id":"0344189bdc1abe99","repo":"flowable/flowable-engine","slug":"cannot-use-taskids-together-with-excludelocalvaria","errorCode":null,"errorMessage":"Cannot use taskIds together with excludeLocalVariables","messagePattern":"Cannot use taskIds together with excludeLocalVariables","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":157,"sourceCode":"            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;\n    }\n\n    @Override","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/HistoricVariableInstanceQueryImpl.java#L139-L175","documentation":"Flowable throws this when HistoricVariableInstanceQuery.taskIds(Collection) is called after excludeLocalVariables() has been set. Task-scoped taskIds queries and the excludeLocalVariables filter are semantically incompatible, so the library rejects the combination eagerly at call time instead of producing a misleading query result. This is an argument-consistency guard in HistoricVariableInstanceQueryImpl.taskIds().","triggerScenarios":"Calling setTaskIds(taskIds) (taskIds setter, line ~157) while the excludeLocalVariables flag is already true — i.e. excludeLocalVariables() was invoked earlier in the fluent chain, or was called before taskIds() in a different order.","commonSituations":"Building a fluent query where both filters are applied conditionally: a developer wants 'all non-local variables for these tasks' and chains .excludeLocalVariables().taskIds(ids). Also happens when refactoring code from taskId-based to taskIds-based queries without removing the exclusion flag.","solutions":["Remove the excludeLocalVariables() call from the query when filtering by taskIds.","Reorder the chain is not enough — the check fires on state, so actually drop one of the two conflicting settings.","If non-local variables are needed per task set, query without excludeLocalVariables and filter results in application code.","Check for conditionally-set flags (e.g. booleans from request parameters) that enable excludeLocalVariables unintentionally."],"exampleFix":"// before\nhistoryService.createHistoricVariableInstanceQuery()\n    .taskIds(taskIds)\n    .excludeLocalVariables()\n    .list();\n\n// after\nhistoryService.createHistoricVariableInstanceQuery()\n    .taskIds(taskIds)\n    .list();","handlingStrategy":"validation","validationCode":"if (excludeLocalVariablesRequested) {\n    throw new IllegalStateException(\"taskIds() cannot be combined with excludeLocalVariables()\");\n}\n// otherwise build the query\nquery.taskIds(taskIds);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep mutually exclusive query flags in separate builder branches.","Never unconditionally append exclusion flags in shared query-builder helpers.","Unit-test each combination of scoping + exclusion flags you use."],"tags":["flowable","query-builder","argument-validation","java"],"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-14T11:17:12.474Z"}