{"record":{"id":"cf797468cbd8a7a8","repo":"flowable/flowable-engine","slug":"cannot-use-taskids-together-with-excludetaskvariab-cf7974","errorCode":null,"errorMessage":"Cannot use taskIds together with excludeTaskVariables","messagePattern":"Cannot use taskIds together with excludeTaskVariables","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricVariableInstanceQueryImpl.java","lineNumber":124,"sourceCode":"            throw new ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n        if (excludeTaskRelated) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\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 ActivitiIllegalArgumentException(\"taskIds is null\");\n        }\n        if (taskIds.isEmpty()) {\n            throw new ActivitiIllegalArgumentException(\"Set of taskIds is empty\");\n        }\n        if (excludeTaskRelated) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskIds together with excludeTaskVariables\");\n        }\n        this.taskIds = taskIds;\n        return this;\n    }\n\n    @Override\n    public HistoricVariableInstanceQuery excludeTaskVariables() {\n        if (taskId != null) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\n        }\n        if (taskIds != null) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskIds together with excludeTaskVariables\");\n        }\n        excludeTaskRelated = true;\n        return this;\n    }\n\n    @Override","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricVariableInstanceQueryImpl.java#L106-L142","documentation":"Like taskId(), taskIds() conflicts with a previously set excludeTaskRelated flag: filtering by a set of tasks and excluding task-related variables cannot both apply. The engine throws ActivitiIllegalArgumentException when taskIds() is called after excludeTaskVariables().","triggerScenarios":"historyService.createHistoricVariableInstanceQuery().excludeTaskVariables().taskIds(set) throws immediately.","commonSituations":"Dynamic query builders appending filters from a config/params map in fixed order, hitting the conflict whenever 'excludeTaskVariables' precedes 'taskIds'; shared/reused query instances.","solutions":["Drop excludeTaskVariables() if you mean to filter by the given task ID set.","Reorder or conditionally apply filters so both options never coexist.","Use separate query objects for the 'exclude' and 'by-task-ids' cases."],"exampleFix":"// before\nquery.excludeTaskVariables().taskIds(ids);\n// after\nquery.taskIds(ids); // choose one mode, not both","handlingStrategy":"validation","validationCode":"boolean excludeTask = cfg.getBoolean(\"excludeTaskVariables\", false);\nif (excludeTask) {\n    query.excludeTaskVariables();\n} else if (taskIds != null && !taskIds.isEmpty()) {\n    query.taskIds(taskIds);\n}","typeGuard":null,"tryCatchPattern":"try { query.taskIds(ids); } catch (org.activiti.engine.ActivitiIllegalArgumentException e) { throw new IllegalStateException(\"taskIds cannot be combined with excludeTaskVariables\", e); }","preventionTips":["Reject conflicting filter flags in request DTO validation before building the query.","Model the two modes as an enum in your API instead of independent booleans.","Write integration tests covering the flag combinations you allow."],"tags":["java","activiti","query-builder","mutually-exclusive"],"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"}