{"record":{"id":"7d73eb237530e11b","repo":"flowable/flowable-engine","slug":"invalid-query-usage-cannot-set-candidategroup-7d73eb","errorCode":null,"errorMessage":"Invalid query usage: cannot set candidateGroup","messagePattern":"Invalid query usage: cannot set candidateGroup","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/TaskQueryImpl.java","lineNumber":532,"sourceCode":"            throw new ActivitiIllegalArgumentException(\"Candidate group is null\");\n        }\n\n        if (candidateGroups != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set both candidateGroup and candidateGroupIn\");\n        }\n\n        if (orActive) {\n            currentOrQueryObject.candidateGroup = candidateGroup;\n        } else {\n            this.candidateGroup = candidateGroup;\n        }\n        return this;\n    }\n\n    @Override\n    public TaskQuery taskCandidateOrAssigned(String userIdForCandidateAndAssignee) {\n        if (candidateGroup != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set candidateGroup\");\n        }\n        if (candidateUser != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query usage: cannot set both candidateGroup and candidateUser\");\n        }\n\n        if (orActive) {\n            currentOrQueryObject.bothCandidateAndAssigned = true;\n            currentOrQueryObject.userIdForCandidateAndAssignee = userIdForCandidateAndAssignee;\n        } else {\n            this.bothCandidateAndAssigned = true;\n            this.userIdForCandidateAndAssignee = userIdForCandidateAndAssignee;\n        }\n\n        return this;\n    }\n\n    @Override\n    public TaskQuery taskCandidateGroupIn(List<String> candidateGroups) {","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/TaskQueryImpl.java#L514-L550","documentation":"taskCandidateOrAssigned(String userIdForCandidateAndAssignee) throws this error when a candidateGroup filter has already been set on the query. The candidate-or-assigned lookup resolves tasks by candidate user OR assignee, which is incompatible with a candidate-group-only filter in the same query. Remove the taskCandidateGroup call or use separate queries.","triggerScenarios":"Calling taskQuery.taskCandidateOrAssigned(userId) after taskQuery.taskCandidateGroup(...) (or a prior candidateGroup set in the same OR block) - checked at TaskQueryImpl.java:532.","commonSituations":"Shared task-list code that always adds a group filter, then product code adds candidate-or-assigned for personal tasks; OR queries where blocks accumulated conflicting filters; migration from group-based to user-based task assignment.","solutions":["Drop taskCandidateGroup when using taskCandidateOrAssigned; the method already covers the user's candidate and assignee view","Run two queries (one group-based, one candidate-or-assigned) and merge results","Refactor the query builder so group and user filtering modes are chosen once, up front"],"exampleFix":"// before\nquery.taskCandidateGroup(\"hr\");\nquery.taskCandidateOrAssigned(\"kermit\"); // throws\n// after\nquery.taskCandidateOrAssigned(\"kermit\");","handlingStrategy":"validation","validationCode":"if (candidateGroup != null && candidateOrAssignedUser != null) {\n    throw new IllegalStateException(\"taskCandidateOrAssigned cannot be combined with taskCandidateGroup\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    query.taskCandidateOrAssigned(userId);\n} catch (ActivitiIllegalArgumentException e) {\n    log.warn(\"candidateGroup already set: {}\", e.getMessage());\n    query = taskService.createTaskQuery().taskCandidateGroup(candidateGroup);\n}","preventionTips":["Choose per query: group-based filtering OR candidate-or-assigned user filtering","Merge results of two separate queries if both views are needed","Audit shared query helpers that unconditionally add candidateGroup"],"tags":["task-query","mutually-exclusive","candidate-group","activiti"],"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"}