{"record":{"id":"988e4e5191f644a0","repo":"flowable/flowable-engine","slug":"provided-user-id-is-null","errorCode":null,"errorMessage":"Provided user id is null","messagePattern":"Provided user id is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/TokenQueryImpl.java","lineNumber":155,"sourceCode":"            throw new FlowableIllegalArgumentException(\"Provided user agent is null\");\n        }\n        this.userAgent = userAgent;\n        return this;\n    }\n\n    @Override\n    public TokenQuery userAgentLike(String userAgentLike) {\n        if (userAgentLike == null) {\n            throw new FlowableIllegalArgumentException(\"Provided userAgentLike is null\");\n        }\n        this.userAgentLike = userAgentLike;\n        return this;\n    }\n\n    @Override\n    public TokenQuery userId(String userId) {\n        if (userId == null) {\n            throw new FlowableIllegalArgumentException(\"Provided user id is null\");\n        }\n        this.userId = userId;\n        return this;\n    }\n\n    @Override\n    public TokenQuery userIdLike(String userIdLike) {\n        if (userIdLike == null) {\n            throw new FlowableIllegalArgumentException(\"Provided userIdLike is null\");\n        }\n        this.userIdLike = userIdLike;\n        return this;\n    }\n\n    @Override\n    public TokenQuery tokenData(String tokenData) {\n        if (tokenData == null) {\n            throw new FlowableIllegalArgumentException(\"Provided token data is null\");","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/TokenQueryImpl.java#L137-L173","documentation":"TokenQueryImpl.userId(String) filters tokens by the owning user's id. A null argument is rejected immediately with FlowableIllegalArgumentException since null cannot be used as an equality criterion in the generated SQL and would silently change query semantics. The library throws at query-construction time to fail fast.","triggerScenarios":"Calling TokenQuery.userId(null), typically identityService.createTokenQuery().userId(currentUserId) where currentUserId is null (e.g. unauthenticated request).","commonSituations":"Using a security-context user id that is null for anonymous sessions; a variable not yet assigned before query building; passing a lookup result that returned null for an unknown user.","solutions":["Verify the user id is resolved before building the query (authenticate the caller first).","Conditionally add the criterion only for non-null ids, or throw your own clearer exception when the id is required.","If you meant 'no such user', check user existence first rather than querying tokens with a null id."],"exampleFix":"// before\nString userId = securityContext.getUserId(); // may be null\nList<Token> tokens = identityService.createTokenQuery().userId(userId).list();\n\n// after\nString userId = securityContext.getUserId();\nif (userId == null) {\n    throw new AuthenticationException(\"User must be authenticated\");\n}\nList<Token> tokens = identityService.createTokenQuery().userId(userId).list();","handlingStrategy":"validation","validationCode":"if (userId == null || userId.isEmpty()) {\n    throw new IllegalStateException(\"Authenticated user id required for token lookup\");\n}\nidentityService.createTokenQuery().userId(userId);","typeGuard":"boolean hasUserId(Principal p) { return p != null && p.getName() != null; }","tryCatchPattern":"try {\n    query.userId(userId);\n} catch (FlowableIllegalArgumentException e) {\n    throw new AuthenticationException(\"Cannot look up tokens without a user id\", e);\n}","preventionTips":["Authenticate/resolve the user before querying their tokens.","Treat a null user id as an authorization failure, not an empty result.","Guard JWT claims or security-context values that may be absent."],"tags":["null-check","query-builder","idm-engine","java"],"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"}