{"record":{"id":"589f5bac73ee436e","repo":"flowable/flowable-engine","slug":"invalid-query-usage-cannot-set-both-tasknamein-an-589f5b","errorCode":null,"errorMessage":"Invalid query usage: cannot set both taskNameIn and taskName","messagePattern":"Invalid query usage: cannot set both taskNameIn and taskName","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricTaskInstanceQueryImpl.java","lineNumber":385,"sourceCode":"        if (inOrStatement) {\n            this.currentOrQueryObject.taskName = taskName;\n        } else {\n            this.taskName = taskName;\n        }\n        return this;\n    }\n\n    @Override\n    public HistoricTaskInstanceQuery taskNameIn(List<String> taskNameList) {\n        if (taskNameList == null) {\n            throw new ActivitiIllegalArgumentException(\"Task name list is null\");\n        }\n        if (taskNameList.isEmpty()) {\n            throw new ActivitiIllegalArgumentException(\"Task name list is empty\");\n        }\n\n        if (taskName != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set both taskNameIn and taskName\");\n        }\n        if (taskNameLike != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set both taskNameIn and taskNameLike\");\n        }\n        if (taskNameLikeIgnoreCase != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set both taskNameIn and taskNameLikeIgnoreCase\");\n        }\n\n        if (inOrStatement) {\n            currentOrQueryObject.taskNameList = taskNameList;\n        } else {\n            this.taskNameList = taskNameList;\n        }\n        return this;\n    }\n\n    @Override\n    public HistoricTaskInstanceQuery taskNameInIgnoreCase(List<String> taskNameList) {","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricTaskInstanceQueryImpl.java#L367-L403","documentation":"Flowable's HistoricTaskInstanceQuery supports two mutually exclusive ways to filter by task name: an exact name (taskName) and a list of names (taskNameIn). When taskNameIn(List) is called, the query validates that no single-name filter was already set and throws ActivitiIllegalArgumentException if taskName is non-null, because combining them would produce an ambiguous WHERE clause.","triggerScenarios":"Calling historicTaskInstanceQuery.taskNameIn(Arrays.asList(\"a\",\"b\")) after previously calling .taskName(\"a\") on the same query object.","commonSituations":"Building a query incrementally with optional criteria where a name filter is sometimes applied via taskName and sometimes via taskNameIn depending on user input, causing both to be set when the code path changes.","solutions":["Choose one filter style: remove the .taskName(...) call before applying taskNameIn, or skip taskNameIn when a single name is known.","Build the query on a fresh HistoricTaskInstanceQuery instance instead of reusing a partially configured one.","In calling code, branch: if the candidate names list size is 1 use taskName(name), otherwise use taskNameIn(names) — never both."],"exampleFix":"// before\nquery.taskName(\"review\");\nquery.taskNameIn(names);\n// after\nif (names.size() == 1) {\n    query.taskName(names.get(0));\n} else {\n    query.taskNameIn(names);\n}","handlingStrategy":"validation","validationCode":"if (names != null && !names.isEmpty()) {\n    if (useExactSingleName) {\n        if (names.size() != 1) throw new IllegalStateException(\"expected exactly one name\");\n        query.taskName(names.get(0));\n    } else {\n        query.taskNameIn(names);\n    }\n}","typeGuard":"boolean canUseTaskNameIn(HistoricTaskInstanceQueryImpl q) { return q.getTaskName() == null; }","tryCatchPattern":"try {\n    query.taskNameIn(names);\n} catch (org.activiti.engine.ActivitiIllegalArgumentException e) {\n    // mutually exclusive with taskName — rebuild query with a single filter\n    query = taskService.createHistoricTaskInstanceQuery().taskNameIn(names);\n}","preventionTips":["Set the task-name filter in exactly one code path per query.","Never reuse a partially configured query object across requests.","Centralize query construction in a builder method that chooses taskName vs taskNameIn."],"tags":["flowable","query","invalid-usage"],"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"}