{"record":{"id":"f052a28da9e57e8a","repo":"flowable/flowable-engine","slug":"userid-is-null-f052a2","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/CreateMembershipCmd.java","lineNumber":40,"sourceCode":"/**\n * @author Tom Baeyens\n */\npublic class CreateMembershipCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    String userId;\n    String groupId;\n\n    public CreateMembershipCmd(String userId, String groupId) {\n        this.userId = userId;\n        this.groupId = groupId;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (userId == null) {\n            throw new FlowableIllegalArgumentException(\"userId is null\");\n        }\n        if (groupId == null) {\n            throw new FlowableIllegalArgumentException(\"groupId is null\");\n        }\n        CommandContextUtil.getMembershipEntityManager(commandContext).createMembership(userId, groupId);\n        return null;\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":49,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/CreateMembershipCmd.java#L22-L49","documentation":"CreateMembershipCmd.execute(CommandContext) throws FlowableIllegalArgumentException when its userId field is null at execution time. A membership links a user to a group, and creating one without a user is invalid. Note the constructor only validates groupId here, so a null userId surfaces when the command runs.","triggerScenarios":"Calling identityService.createMembership(null, groupId) — the command executes and fails its userId check.","commonSituations":"Bulk user/group synchronization jobs where a user record failed to load or the id field is null in the source data.","solutions":["Pass a non-null userId that references an existing user.","Create the user first (identityService.newUser/saveUser) before creating the membership.","Validate both ids before calling createMembership."],"exampleFix":"// before\nidentityService.createMembership(user.getId(), group.getId()); // user.getId() null\n// after\nif (user.getId() != null) {\n    identityService.createMembership(user.getId(), group.getId());\n} else {\n    identityService.saveUser(user); // persist to obtain the id first\n    identityService.createMembership(user.getId(), group.getId());\n}","handlingStrategy":"validation","validationCode":"if (userId != null && groupId != null) { identityService.createMembership(userId, groupId); }","typeGuard":"boolean canCreateMembership(String userId, String groupId) { return userId != null && groupId != null; }","tryCatchPattern":"try { identityService.createMembership(userId, groupId); } catch (FlowableIllegalArgumentException e) { log.error(\"Membership needs non-null userId and groupId\", e); }","preventionTips":["Persist the user first so its id is non-null","Null-check both ids before creating memberships","Validate source data in sync jobs before issuing IDM calls"],"tags":["flowable","idm","null-argument","membership","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-14T11:17:12.474Z"}