{"record":{"id":"0067b17de64e30e5","repo":"flowable/flowable-engine","slug":"userid-is-null-0067b1","errorCode":null,"errorMessage":"userId is null","messagePattern":"userId is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/CreateUserCmd.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.User;\nimport org.flowable.idm.engine.impl.util.CommandContextUtil;\n\n/**\n * @author Tom Baeyens\n */\npublic class CreateUserCmd implements Command<User>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    protected String userId;\n\n    public CreateUserCmd(String userId) {\n        if (userId == null) {\n            throw new FlowableIllegalArgumentException(\"userId is null\");\n        }\n        this.userId = userId;\n    }\n\n    @Override\n    public User execute(CommandContext commandContext) {\n        return CommandContextUtil.getUserEntityManager(commandContext).createNewUser(userId);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":45,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/CreateUserCmd.java#L17-L45","documentation":"CreateUserCmd's constructor rejects a null userId immediately. The IDM engine requires a user identifier to create or operate on a User entity, so a null id is treated as a programming/API-usage error and fails fast via FlowableIllegalArgumentException before execute() runs.","triggerScenarios":"Calling new CreateUserCmd(null), or calling IdentityService.newUser(null) / user-service endpoints that construct this command with a null user id.","commonSituations":"Username sourced from an HTTP request body, SSO claim, or LDAP attribute that is missing; batch user provisioning where some records lack ids; migration scripts mapping columns that are null for some rows.","solutions":["Supply a non-null userId when constructing CreateUserCmd or when calling the IdentityService wrapper.","Validate the id at the application boundary (e.g. require username in REST payload) before invoking the engine.","If the id is derived from another system, skip or reject records with null ids instead of passing them to the engine.","Wrap the call in a try-catch for FlowableIllegalArgumentException to convert it into a domain-level validation error."],"exampleFix":"// before\nidentityService.saveUser(identityService.newUser(userId)); // userId may be null\n\n// after\nObjects.requireNonNull(userId, \"userId is required\");\nidentityService.saveUser(identityService.newUser(userId));","handlingStrategy":"validation","validationCode":"if (userId == null || userId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"userId must be a non-empty String before creating a user\");\n}","typeGuard":"boolean hasValidUserId(String userId) {\n    return userId != null && !userId.trim().isEmpty();\n}","tryCatchPattern":"try {\n    identityService.saveUser(identityService.newUser(userId));\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"userId is null\")) {\n        throw new InvalidRequestException(\"User id must not be null\");\n    }\n    throw e;\n}","preventionTips":["Enforce @NotNull/@NotBlank on user id DTOs at the REST layer.","Reject records with missing ids during bulk provisioning before touching the engine.","Use Objects.requireNonNull near the call site to fail with a descriptive message.","Keep id derivation logic (SSO/LDAP mapping) covered by tests so nulls surface early."],"tags":["flowable","idm","null-check","user"],"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"}