{"record":{"id":"d0c0eb884454a43b","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null","errorCode":null,"errorMessage":"caseInstanceId is null","messagePattern":"caseInstanceId is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java","lineNumber":53,"sourceCode":"\n    protected String userId;\n\n    protected String groupId;\n\n    protected String type;\n\n    public AddIdentityLinkForCaseInstanceCmd(String caseInstanceId, String userId, String groupId, String type) {\n        validateParams(caseInstanceId, userId, groupId, type);\n        this.caseInstanceId = caseInstanceId;\n        this.userId = userId;\n        this.groupId = groupId;\n        this.type = type;\n    }\n\n    protected void validateParams(String caseInstanceId, String userId, String groupId, String type) {\n\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new FlowableIllegalArgumentException(\"type is required when adding a new case instance identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new FlowableIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntityManager caseInstanceEntityManager = cmmnEngineConfiguration.getCaseInstanceEntityManager();\n        CaseInstanceEntity caseInstance = caseInstanceEntityManager.findById(caseInstanceId);\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java#L35-L71","documentation":"AddIdentityLinkForCaseDefinitionCmd's case-instance counterpart validates that a non-null caseInstanceId is supplied when attaching an identity link to a case instance. A null id leaves no target scope, so validateParams throws FlowableIllegalArgumentException.","triggerScenarios":"Calling cmmnRuntimeService.addIdentityLink(caseInstanceId, userId, groupId, type) with a null caseInstanceId — e.g. the instance variable was never set, or the case was started elsewhere and its id wasn't propagated.","commonSituations":"Workflow orchestration code losing the case instance id between steps, REST callers omitting the instance id, or confusing taskId with caseInstanceId variables.","solutions":["Capture the id returned by cmmnRuntimeService.startCaseInstance(...) and pass it to identity-link calls","Null-check the instance id at the caller before invoking the API","Use caseInstance.getId() from a CaseInstance query result rather than a hand-copied value"],"exampleFix":"// before\nruntimeService.addIdentityLink(caseInstanceId, userId, null, IdentityLinkType.PARTICIPANT);\n// after\nif (caseInstanceId == null) throw new IllegalArgumentException(\"caseInstanceId is required\");\nruntimeService.addIdentityLink(caseInstanceId, userId, null, IdentityLinkType.PARTICIPANT);","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null) throw new IllegalArgumentException(\"caseInstanceId is required\");\nruntimeService.addIdentityLink(caseInstanceId, userId, groupId, type);","typeGuard":"boolean hasInstanceId(String id) { return id != null && !id.isBlank(); }","tryCatchPattern":"try {\n    runtimeService.addIdentityLink(caseInstanceId, userId, groupId, type);\n} catch (FlowableIllegalArgumentException e) {\n    throw new BadRequestException(\"caseInstanceId missing: \" + e.getMessage());\n}","preventionTips":["Store the id returned by startCaseInstance and pass it explicitly","Don't confuse taskId with caseInstanceId variables","Validate instance ids at the API boundary"],"tags":["cmmn","identity-link","null-check","case-instance"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}