{"record":{"id":"84d31ab1e919ef35","repo":"flowable/flowable-engine","slug":"candidate-user-is-null-84d31a","errorCode":null,"errorMessage":"Candidate user is null","messagePattern":"Candidate user is null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-task-service/src/main/java/org/flowable/task/service/impl/TaskQueryImpl.java","lineNumber":578,"sourceCode":"            if (delegationState == null) {\n                currentOrQueryObject.noDelegationState = true;\n            } else {\n                currentOrQueryObject.delegationState = delegationState;\n            }\n        } else {\n            if (delegationState == null) {\n                this.noDelegationState = true;\n            } else {\n                this.delegationState = delegationState;\n            }\n        }\n        return this;\n    }\n\n    @Override\n    public TaskQueryImpl taskCandidateUser(String candidateUser) {\n        if (candidateUser == null) {\n            throw new FlowableIllegalArgumentException(\"Candidate user is null\");\n        }\n\n        if (orActive) {\n            currentOrQueryObject.candidateUser = candidateUser;\n        } else {\n            this.candidateUser = candidateUser;\n        }\n\n        return this;\n    }\n\n    @Override\n    public TaskQueryImpl taskInvolvedUser(String involvedUser) {\n        if (involvedUser == null) {\n            throw new FlowableIllegalArgumentException(\"Involved user is null\");\n        }\n        if (orActive) {\n            currentOrQueryObject.involvedUser = involvedUser;","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-task-service/src/main/java/org/flowable/task/service/impl/TaskQueryImpl.java#L560-L596","documentation":"TaskQueryImpl.taskCandidateUser(String) rejects a null candidate user. The candidate-user filter drives the identity-link join in the query; a null user would produce meaningless SQL, so Flowable validates eagerly and throws FlowableIllegalArgumentException.","triggerScenarios":"taskQuery.taskCandidateUser(null) — typically when the current user is unknown: no authenticated principal, an unauthenticated request, or a user variable never set.","commonSituations":"Calling taskService.createTaskQuery().taskCandidateUser(userId) in a scheduled/background job with no user context; a security context returning null user in anonymous flows; upgrading or wiring identity services so userId is no longer populated.","solutions":["Resolve the user ID first (e.g. from the security context) and refuse to build the query when it is null.","Skip the candidateUser filter when there is no user, using a different query strategy (e.g. by group or by process).","Fix the authentication/user-resolution code so a real user ID is always available where this query runs."],"exampleFix":"// before\ntaskQuery.taskCandidateUser(securityService.getCurrentUser());\n\n// after\nString userId = securityService.getCurrentUser();\nif (userId != null) {\n    taskQuery.taskCandidateUser(userId);\n}","handlingStrategy":"validation","validationCode":"if (candidateUser == null || candidateUser.isEmpty()) { throw new IllegalStateException(\"candidateUser required for this query\"); }\ntaskQuery.taskCandidateUser(candidateUser);","typeGuard":"boolean usable = candidateUser != null && !candidateUser.isEmpty();","tryCatchPattern":"try {\n    taskQuery.taskCandidateUser(userId);\n} catch (FlowableIllegalArgumentException e) {\n    if (!\"Candidate user is null\".equals(e.getMessage())) throw e;\n    logger.warn(\"No authenticated user; cannot query candidate tasks\");\n    return Collections.emptyList();\n}","preventionTips":["Resolve the user ID from the security context before creating the query and handle 'no user' explicitly.","Avoid running candidate-user queries in background jobs without a user context; use group or process-based queries instead.","Fail fast at the controller/service boundary when a task inbox is requested without authentication."],"tags":["flowable","task-query","null-argument","validation"],"backgroundTag":"null-argument","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"}