{"record":{"id":"35b21f7ecb8c3c10","repo":"flowable/flowable-engine","slug":"userid-and-groupid-cannot-both-be-null-35b21f","errorCode":null,"errorMessage":"userId and groupId cannot both be null","messagePattern":"userId and groupId cannot both be null","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessDefinitionCmd.java","lineNumber":50,"sourceCode":"\n    protected String userId;\n\n    protected String groupId;\n\n    public AddIdentityLinkForProcessDefinitionCmd(String processDefinitionId, String userId, String groupId) {\n        validateParams(userId, groupId, processDefinitionId);\n        this.processDefinitionId = processDefinitionId;\n        this.userId = userId;\n        this.groupId = groupId;\n    }\n\n    protected void validateParams(String userId, String groupId, String processDefinitionId) {\n        if (processDefinitionId == null) {\n            throw new ActivitiIllegalArgumentException(\"processDefinitionId is null\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new ActivitiIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ProcessDefinitionEntity processDefinition = commandContext\n                .getProcessDefinitionEntityManager()\n                .findProcessDefinitionById(processDefinitionId);\n\n        if (processDefinition == null) {\n            throw new ActivitiObjectNotFoundException(\"Cannot find process definition with id \" + processDefinitionId, ProcessDefinition.class);\n        }\n\n        processDefinition.addIdentityLink(userId, groupId);\n\n        return null;\n    }\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessDefinitionCmd.java#L32-L68","documentation":"Parameter validation in AddIdentityLinkForProcessDefinitionCmd.validateParams: an identity link needs at least one target, so userId and groupId may not both be null (processDefinitionId null is checked in the same helper).","triggerScenarios":"Calling repositoryService.addUserIdentityLinkForProcessDefinition(id, null) (userId overload with null) or constructing the command with both userId and groupId null.","commonSituations":"Both user and group variables were resolved from empty configuration or a form with unfilled fields; a refactor removed the default group id; intending to delete a link but using the add command.","solutions":["Provide either a userId or a groupId — at least one must be non-null","Validate the input before calling; reject requests with no user and no group","If removal is the goal, use the corresponding delete/remove identity link API instead"],"exampleFix":"// before\nrepositoryService.addGroupIdentityLinkForProcessDefinition(defId, groupId); // groupId null\n// after\nif (groupId == null && userId == null) {\n    throw new IllegalArgumentException(\"Provide userId or groupId\");\n}\nrepositoryService.addGroupIdentityLinkForProcessDefinition(defId, groupId);","handlingStrategy":"validation","validationCode":"if (userId == null && groupId == null) {\n    throw new IllegalArgumentException(\"At least one of userId or groupId must be provided\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    repositoryService.addIdentityLinkForProcessDefinition(defId, userId, groupId, type);\n} catch (ActivitiIllegalArgumentException e) {\n    if (e.getMessage().contains(\"both be null\")) {\n        // reject or supply a default group\n    } else { throw e; }\n}","preventionTips":["Reject form/REST payloads that omit both user and group","Provide a fallback default group for unassigned links","Use remove/delete APIs for un-linking, not the add command with nulls"],"tags":["null-argument","identity-link","process-definition","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T16:30:33.424Z"}