{"record":{"id":"0eaf9c985784bd88","repo":"flowable/flowable-engine","slug":"cannot-assign-a-userid-to-a-task-assignment-that-a-0eaf9c","errorCode":null,"errorMessage":"Cannot assign a userId to a task assignment that already has a groupId","messagePattern":"Cannot assign a userId to a task assignment that already has a groupId","errorType":"validation","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/entity/HistoricIdentityLinkEntity.java","lineNumber":115,"sourceCode":"    }\n\n    @Override\n    public String getType() {\n        return type;\n    }\n\n    public void setType(String type) {\n        this.type = type;\n    }\n\n    @Override\n    public String getUserId() {\n        return userId;\n    }\n\n    public void setUserId(String userId) {\n        if (this.groupId != null && userId != null) {\n            throw new ActivitiException(\"Cannot assign a userId to a task assignment that already has a groupId\");\n        }\n        this.userId = userId;\n    }\n\n    @Override\n    public String getGroupId() {\n        return groupId;\n    }\n\n    public void setGroupId(String groupId) {\n        if (this.userId != null && groupId != null) {\n            throw new ActivitiException(\"Cannot assign a groupId to a task assignment that already has a userId\");\n        }\n        this.groupId = groupId;\n    }\n\n    @Override\n    public String getTaskId() {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/entity/HistoricIdentityLinkEntity.java#L97-L133","documentation":"A HistoricIdentityLinkEntity represents one assignment/identity link on a historic task and must be either user-based or group-based, never both. setUserId rejects assigning a userId when a groupId is already present, since the persisted row would become ambiguous.","triggerScenarios":"Calling setUserId (directly or via entity manipulation / custom history mapping) on a HistoricIdentityLinkEntity whose groupId field is already non-null and passing a non-null userId.","commonSituations":"Custom code copying IdentityLink data between entities without clearing the opposite field; history-level configuration or event listeners that mutate identity link entities; data import/migration scripts that reuse an entity for both group and user assignments.","solutions":["Create a separate entity for the user assignment instead of reusing one that already holds a groupId.","Set groupId to null before calling setUserId if the link really should switch to user-based.","Distinguish candidate-group links from assignee links in your mapping code: one IdentityLink = one principal type."],"exampleFix":"// before\nlink.setGroupId(\"management\");\nlink.setUserId(\"kermit\"); // throws\n\n// after\nHistoricIdentityLinkEntity groupLink = ...; groupLink.setGroupId(\"management\");\nHistoricIdentityLinkEntity userLink = ...; userLink.setUserId(\"kermit\");","handlingStrategy":"type-guard","validationCode":"if (link.getGroupId() != null && userId != null) {\n    throw new IllegalArgumentException(\"link already group-based\");\n}","typeGuard":"function canSetUserId(link) {\n  return link.getGroupId() == null;\n}","tryCatchPattern":"try {\n    link.setUserId(userId);\n} catch (ActivitiException e) {\n    link = createNewIdentityLink(); // start a fresh link for the user\n    link.setUserId(userId);\n}","preventionTips":["One identity link = one principal type (user XOR group)","Use taskService.addUserIdentityLink/addCandidateGroup instead of entity mutation","Clear the opposite field before switching link type"],"tags":["identity-link","history","assignment"],"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"}