{"record":{"id":"9ae62b72bd9ff625","repo":"Activiti/Activiti","slug":"type-is-required-when-adding-a-new-process-instanc","errorCode":null,"errorMessage":"type is required when adding a new process instance identity link","messagePattern":"type is required when adding a new process instance identity link","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessInstanceCmd.java","lineNumber":70,"sourceCode":"        String groupId,\n        String type,\n        byte[] details\n    ) {\n        validateParams(processInstanceId, userId, groupId, type);\n        this.processInstanceId = processInstanceId;\n        this.userId = userId;\n        this.groupId = groupId;\n        this.type = type;\n        this.details = details;\n    }\n\n    protected void validateParams(String processInstanceId, String userId, String groupId, String type) {\n        if (processInstanceId == null) {\n            throw new ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new ActivitiIllegalArgumentException(\n                \"type is required when adding a new process instance identity link\"\n            );\n        }\n\n        if (userId == null && groupId == null) {\n            throw new ActivitiIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n    }\n\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();\n        ExecutionEntity processInstance = executionEntityManager.findById(processInstanceId);\n\n        if (processInstance == null) {\n            throw new ActivitiObjectNotFoundException(\n                \"Cannot find process instance with id \" + processInstanceId,\n                ExecutionEntity.class\n            );","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessInstanceCmd.java#L52-L88","documentation":"Activiti throws ActivitiIllegalArgumentException when the identity link type is null in AddIdentityLinkForProcessInstanceCmd. The type (e.g. candidate, participant) is required to classify the link. validateParams enforces it right after the processInstanceId check.","triggerScenarios":"Calling addUserIdentityLink/addGroupIdentityLink on a process instance with type=null, e.g. a type variable loaded from config or task data that is unset.","commonSituations":"Custom identity-link types read from properties files that failed to load; typos where the constant referenced is actually null; reflection-based invocation passing null.","solutions":["Pass a non-null type such as IdentityLinkType.CANDIDATE, IdentityLinkType.PARTICIPANT, or a custom value.","Define custom type constants instead of raw strings to avoid nulls.","Validate the type parameter in the caller."],"exampleFix":"// before\nruntimeService.addUserIdentityLink(pid, userId, null, linkType); // linkType null\n// after\nString type = linkType != null ? linkType : IdentityLinkType.PARTICIPANT;\nruntimeService.addUserIdentityLink(pid, userId, null, type);","handlingStrategy":"validation","validationCode":"if (linkType == null) {\n    throw new IllegalArgumentException(\"Identity link type is required\");\n}","typeGuard":"boolean hasLinkType(String type) { return type != null && !type.trim().isEmpty(); }","tryCatchPattern":"try {\n    runtimeService.addUserIdentityLink(pid, userId, groupId, type);\n} catch (ActivitiIllegalArgumentException e) {\n    log.error(\"Identity link type missing: {}\", e.getMessage());\n}","preventionTips":["Use IdentityLinkType constants instead of raw strings","Load custom types from validated configuration","Reject empty types early in your service layer"],"tags":["java","activiti","null-argument","validation"],"backgroundTag":"missing-required-argument","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"}