{"record":{"id":"23a616e39f3e2dff","repo":"flowable/flowable-engine","slug":"tokenid-is-null","errorCode":null,"errorMessage":"tokenId is null","messagePattern":"tokenId is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/CreateTokenCmd.java","lineNumber":35,"sourceCode":"\nimport org.flowable.common.engine.api.FlowableIllegalArgumentException;\nimport org.flowable.common.engine.impl.interceptor.Command;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\nimport org.flowable.idm.api.Token;\nimport org.flowable.idm.engine.impl.util.CommandContextUtil;\n\n/**\n * @author Tijs Rademakers\n */\npublic class CreateTokenCmd implements Command<Token>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    protected String tokenId;\n\n    public CreateTokenCmd(String tokenId) {\n        if (tokenId == null) {\n            throw new FlowableIllegalArgumentException(\"tokenId is null\");\n        }\n        this.tokenId = tokenId;\n    }\n\n    @Override\n    public Token execute(CommandContext commandContext) {\n        return CommandContextUtil.getTokenEntityManager(commandContext).createNewToken(tokenId);\n    }\n\n}\n","sourceCodeStart":17,"sourceCodeEnd":46,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/CreateTokenCmd.java#L17-L46","documentation":"CreateTokenCmd's constructor validates that a tokenId is supplied before the command is executed by the Flowable IDM engine. If you pass null, the command refuses to run because a token cannot be created or looked up without an identifier. This fail-fast check happens at command construction time, before any database access.","triggerScenarios":"Calling new CreateTokenCmd(null), or invoking an API path that builds this command with a null token id, e.g. IdentityService.createTokenQuery()-style flows or ManagementService APIs that accept a token id which is null.","commonSituations":"A token id variable read from config, a request parameter, or a previous lookup result is null (entity not found upstream); refactored code paths that no longer populate the id; deserialized DTOs with missing token id fields.","solutions":["Ensure the token id passed to CreateTokenCmd (or the wrapping IdentityService API) is a non-null String before invoking.","If the id comes from a prior lookup, check that the entity exists (query singleResult() != null) before using its id.","Guard the call site: throw a descriptive application exception when the token id is absent so the root cause is visible.","If the token should be auto-generated, use the overload/API that creates a token without requiring a caller-supplied id (TokenServiceImpl.newToken / saveToken)."],"exampleFix":"// before\ncommandExecutor.execute(new CreateTokenCmd(tokenId)); // tokenId may be null\n\n// after\nif (tokenId == null) {\n    throw new IllegalArgumentException(\"tokenId must be provided\");\n}\ncommandExecutor.execute(new CreateTokenCmd(tokenId));","handlingStrategy":"validation","validationCode":"if (tokenId == null || tokenId.isEmpty()) {\n    throw new IllegalArgumentException(\"tokenId must be a non-empty String before creating/looking up a token\");\n}","typeGuard":"boolean hasValidTokenId(String tokenId) {\n    return tokenId != null && !tokenId.isEmpty();\n}","tryCatchPattern":"try {\n    identityService.saveToken(identityService.newTokenBuilder(tokenId).create());\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"tokenId is null\")) {\n        throw new InvalidRequestException(\"Token id must not be null\");\n    }\n    throw e;\n}","preventionTips":["Never construct engine commands directly; go through IdentityService wrappers and validate ids there.","Validate request payloads (Bean Validation @NotNull on token id fields) before calling the engine.","When an id comes from a prior lookup, assert the lookup result is non-null first.","Add unit tests covering null-id API calls."],"tags":["flowable","idm","null-check","token"],"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"}