{"record":{"id":"c2a69aba0daa2f52","repo":"flowable/flowable-engine","slug":"type-is-required-when-adding-a-new-process-instanc-c2a69a","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":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessInstanceCmd.java","lineNumber":53,"sourceCode":"\n    protected String type;\n\n    public AddIdentityLinkForProcessInstanceCmd(String processInstanceId, String userId, String groupId, String type) {\n        validateParams(processInstanceId, userId, groupId, type);\n        this.processInstanceId = processInstanceId;\n        this.userId = userId;\n        this.groupId = groupId;\n        this.type = type;\n    }\n\n    protected void validateParams(String processInstanceId, String userId, String groupId, String type) {\n\n        if (processInstanceId == null) {\n            throw new ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new ActivitiIllegalArgumentException(\"type is required when adding a new process instance identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new ActivitiIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n\n        ExecutionEntity processInstance = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n        if (processInstance == null) {\n            throw new ActivitiObjectNotFoundException(\"Cannot find process instance with id \" + processInstanceId, ExecutionEntity.class);\n        }\n\n        processInstance.addIdentityLink(userId, groupId, type);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddIdentityLinkForProcessInstanceCmd.java#L35-L71","documentation":"AddIdentityLinkForProcessInstanceCmd requires a non-null link type when adding a process instance identity link. validateParams throws ActivitiIllegalArgumentException because without a type the link has no semantics and cannot be stored.","triggerScenarios":"Calling runtimeService.addUserIdentityLinkForProcessInstance(pid, userId, null) or the group variant with a null type; constructing the command with type == null.","commonSituations":"Link type read from configuration/JSON where the field is absent; variable shadowing or swapped arguments; assuming a default type is applied automatically (none is).","solutions":["Pass an explicit type such as IdentityLinkType.PARTICIPANT or a custom 'starter' style type","Default the type when null: type == null ? IdentityLinkType.PARTICIPANT : type","Validate request payloads for the type field at the API boundary"],"exampleFix":"// before\nruntimeService.addUserIdentityLinkForProcessInstance(pid, userId, linkType); // null\n// after\nString t = linkType != null ? linkType : IdentityLinkType.PARTICIPANT;\nruntimeService.addUserIdentityLinkForProcessInstance(pid, userId, t);","handlingStrategy":"validation","validationCode":"if (linkType == null) {\n    linkType = IdentityLinkType.PARTICIPANT; // or reject\n}","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.addUserIdentityLinkForProcessInstance(pid, userId, null, type);\n} catch (ActivitiIllegalArgumentException e) {\n    if (e.getMessage().contains(\"type is required\")) {\n        runtimeService.addUserIdentityLinkForProcessInstance(pid, userId, null, IdentityLinkType.PARTICIPANT);\n    } else { throw e; }\n}","preventionTips":["Centralize link-type selection in one helper that guarantees a default","Require the type field in API payloads and reject missing values","Use IdentityLinkType constants, not ad-hoc strings"],"tags":["null-argument","identity-link","process-instance","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-18T11:17:12.947Z"}