{"record":{"id":"ce4d0adb78b81b40","repo":"Activiti/Activiti","slug":"identityidtype-allowed-values-are-1-and-2","errorCode":null,"errorMessage":"identityIdType allowed values are 1 and 2","messagePattern":"identityIdType allowed values are 1 and 2","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkCmd.java","lineNumber":78,"sourceCode":"    protected void validateParams(String taskId, String identityId, int identityIdType, String identityType) {\n        if (taskId == null) {\n            throw new ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n\n        if (identityType == null) {\n            throw new ActivitiIllegalArgumentException(\"type is required when adding a new task identity link\");\n        }\n\n        if (\n            identityId == null &&\n            (identityIdType == IDENTITY_GROUP ||\n                (!IdentityLinkType.ASSIGNEE.equals(identityType) && !IdentityLinkType.OWNER.equals(identityType)))\n        ) {\n            throw new ActivitiIllegalArgumentException(\"identityId is null\");\n        }\n\n        if (identityIdType != IDENTITY_USER && identityIdType != IDENTITY_GROUP) {\n            throw new ActivitiIllegalArgumentException(\"identityIdType allowed values are 1 and 2\");\n        }\n    }\n\n    protected Void execute(CommandContext commandContext, TaskEntity task) {\n        boolean assignedToNoOne = false;\n        if (IdentityLinkType.ASSIGNEE.equals(identityType)) {\n            commandContext.getTaskEntityManager().changeTaskAssignee(task, identityId);\n            assignedToNoOne = identityId == null;\n        } else if (IdentityLinkType.OWNER.equals(identityType)) {\n            commandContext.getTaskEntityManager().changeTaskOwner(task, identityId);\n        } else if (IDENTITY_USER == identityIdType) {\n            task.addUserIdentityLink(identityId, identityType, details);\n        } else if (IDENTITY_GROUP == identityIdType) {\n            task.addGroupIdentityLink(identityId, identityType);\n        }\n\n        boolean forceNullUserId = false;\n        if (assignedToNoOne) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkCmd.java#L60-L96","documentation":"validateParams() last check: identityIdType must be exactly IDENTITY_USER (1) or IDENTITY_GROUP (2). Any other int (typically 0 from an uninitialized field or an out-of-range value) triggers ActivitiIllegalArgumentException. This API is an older integer-typed variant kept alongside the string IdentityLinkType overloads.","triggerScenarios":"Calling the int-based addIdentityLink variant (taskService.addIdentityLink-like overloads taking an int) with 0, 3, or any value other than 1 or 2 — commonly an unset field defaulting to 0.","commonSituations":"Hand-maintained mappings converting user/group roles to ints with no default; values loaded from external config where 'user'/'group' strings weren't recognized; legacy integrations using wrong numeric codes.","solutions":["Pass only IDENTITY_USER (1) or IDENTITY_GROUP (2) constants from the class, never raw literals.","Prefer the string-based overloads (taskService.addUserIdentityLink / addGroupIdentityLink) which avoid the int typing entirely.","Validate/mapping-lookup the int before calling; reject unknown role names at configuration load time.","Fix default initialization so the field defaults to a valid code rather than 0."],"exampleFix":"// before\nint identityIdType = 0; // defaults to 0 -> rejected\n// after\nint identityIdType = isGroup ? AddIdentityLinkCmd.IDENTITY_GROUP : AddIdentityLinkCmd.IDENTITY_USER;","handlingStrategy":"validation","validationCode":"if (identityIdType != IDENTITY_USER && identityIdType != IDENTITY_GROUP) {\n    throw new IllegalArgumentException(\"identityIdType must be 1 (user) or 2 (group)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    taskService.addIdentityLink(taskId, identityId, identityIdType, identityType);\n} catch (ActivitiIllegalArgumentException e) {\n    log.error(\"identityIdType must be 1 or 2\", e);\n}","preventionTips":["Only use the IDENTITY_USER/IDENTITY_GROUP constants, never magic numbers.","Prefer string-based overloads (addUserIdentityLink/addGroupIdentityLink) over the int variant.","Map external role names to these constants once, with validation at load time."],"tags":["activiti","identity-link","invalid-enum-value","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}