{"record":{"id":"4acfc27c8392fe1b","repo":"flowable/flowable-engine","slug":"userid-and-groupid-cannot-both-be-null-4acfc2","errorCode":null,"errorMessage":"userId and groupId cannot both be null","messagePattern":"userId and groupId cannot both be null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java","lineNumber":61,"sourceCode":"        validateParams(caseInstanceId, userId, groupId, type);\n        this.caseInstanceId = caseInstanceId;\n        this.userId = userId;\n        this.groupId = groupId;\n        this.type = type;\n    }\n\n    protected void validateParams(String caseInstanceId, String userId, String groupId, String type) {\n\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new FlowableIllegalArgumentException(\"type is required when adding a new case instance identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new FlowableIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntityManager caseInstanceEntityManager = cmmnEngineConfiguration.getCaseInstanceEntityManager();\n        CaseInstanceEntity caseInstance = caseInstanceEntityManager.findById(caseInstanceId);\n\n        if (caseInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find case instance with id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n\n        IdentityLinkUtil.createCaseInstanceIdentityLink(caseInstance, userId, groupId, type, cmmnEngineConfiguration);\n        \n        return null;\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java#L43-L79","documentation":"AddIdentityLinkForCaseInstanceCmd.validateParams throws FlowableIllegalArgumentException when both userId and groupId are null. An identity link must point to at least one principal (user or group); creating one referencing neither would be meaningless, so the command rejects it up front.","triggerScenarios":"Calling addIdentityLinkForCaseInstance (or constructing the command) with type set but both userId and groupId null/omitted — e.g. a REST call supplying only the type, or variables holding the assignee/group both resolving to null.","commonSituations":"Optional assignee not filled in by the caller; both user and group fields left blank in a UI-driven API request; code intended to add a group link but the group variable was never set.","solutions":["Provide either a userId or a groupId (at least one non-null) when adding the identity link","Validate user/group presence in caller code before invoking the API","If the intent was a link to neither, use a different mechanism (e.g. case metadata) instead of an identity link"],"exampleFix":"// before\ncmmnRuntimeService.addIdentityLinkForCaseInstance(caseInstanceId, null, null, \"participant\");\n// after\ncmmnRuntimeService.addIdentityLinkForCaseInstance(caseInstanceId, \"kermit\", null, \"participant\");","handlingStrategy":"validation","validationCode":"if (userId == null && groupId == null) throw new IllegalArgumentException(\"Either userId or groupId must be provided\");","typeGuard":"boolean hasPrincipal(String userId, String groupId) { return userId != null || groupId != null; }","tryCatchPattern":"try {\n    cmmnRuntimeService.addIdentityLinkForCaseInstance(caseId, userId, groupId, type);\n} catch (FlowableIllegalArgumentException e) {\n    log.warn(\"Cannot add identity link: {}\", e.getMessage());\n}","preventionTips":["Ensure UI forms require at least one of user or group","Check variables holding assignee/group are set before linking","Write a unit test covering both-null input"],"tags":["flowable","cmmn","identity-link","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}