{"record":{"id":"e94cd22064e6d245","repo":"flowable/flowable-engine","slug":"either-set-the-user-id-or-the-group-id-for-an-iden-e94cd2","errorCode":null,"errorMessage":"Either set the user id or the group id for an identity link, but not both the same time.","messagePattern":"Either set the user id or the group id for an identity link, but not both the same time\\.","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AbstractProcessInstanceIdentityLinkCmd.java","lineNumber":77,"sourceCode":"    /**\n     * Creates a new identity link entry for the given process instance, which can either be a user or group based one, but not both the same time.\n     * If both the user and group ids are null, no new identity link is created.\n     *\n     * @param commandContext the command context within which to perform the identity link creation\n     * @param processInstanceId the id of the process instance to create an identity link for\n     * @param userId the user id if this is a user based identity link, otherwise null\n     * @param groupId the group id if this is a group based identity link, otherwise null\n     * @param identityType the type of identity link (e.g. owner or assignee, etc)\n     */\n    protected void createIdentityLinkType(CommandContext commandContext, String processInstanceId, String userId, String groupId, String identityType) {\n        // if both user and group ids are null, don't create an identity link\n        if (userId == null && groupId == null) {\n            return;\n        }\n\n        // if both are set the same time, throw an exception as this is not allowed\n        if (userId != null && groupId != null) {\n            throw new FlowableIllegalArgumentException(\"Either set the user id or the group id for an identity link, but not both the same time.\");\n        }\n\n        ExecutionEntity processInstanceEntity = getProcessInstanceEntity(commandContext, processInstanceId);\n        IdentityLinkUtil.createProcessInstanceIdentityLink(processInstanceEntity, userId, groupId, identityType);\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":84,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AbstractProcessInstanceIdentityLinkCmd.java#L59-L84","documentation":"createIdentityLinkType allows an identity link to reference either a user or a group, not both. If both userId and groupId are non-null, it throws FlowableIllegalArgumentException before creating the link. If both are null, the call is a silent no-op.","triggerScenarios":"Calling an add-identity-link command/API for a process instance with both userId and groupId populated (e.g. UI sending both fields, or code that sets defaults for both).","commonSituations":"Front-end forms with both 'user' and 'group' inputs filled; copying parameters into both arguments; framework binding that populates both request fields; confusion between Flowable identity link and other APIs that accept both.","solutions":["Set exactly one of userId or groupId; create two separate identity links if both are genuinely needed.","Add client-side validation to reject payloads with both fields set.","In UI code, make the user/group selection mutually exclusive or clear the other field on selection."],"exampleFix":"// before\nruntimeService.addUserIdentityLinkToProcessInstance(piId, userId, groupId, \"participant\"); // both set\n// after\nif (userId != null) {\n    runtimeService.addUserIdentityLinkToProcessInstance(piId, userId, null, \"participant\");\n} else {\n    runtimeService.addGroupIdentityLinkToProcessInstance(piId, groupId, \"participant\");\n}","handlingStrategy":"validation","validationCode":"if (userId != null && groupId != null) {\n    throw new IllegalArgumentException(\"Set user or group, not both\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate input payloads so userId and groupId are mutually exclusive","Create separate identity links for user and group when both are needed","Make UI selection user-XOR-group"],"tags":["flowable","identity-link","argument-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-18T11:17:12.947Z"}