{"record":{"id":"bd83fd30f4d3ff47","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-bd83fd","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/SetVariableAsyncCmd.java","lineNumber":38,"sourceCode":"import org.flowable.common.engine.impl.interceptor.Command;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\n\npublic class SetVariableAsyncCmd extends AbstractSetVariableAsyncCmd implements Command<Void> {\n    \n    protected String caseInstanceId;\n    protected String variableName;\n    protected Object variableValue;\n    \n    public SetVariableAsyncCmd(String caseInstanceId, String variableName, Object variableValue) {\n        this.caseInstanceId = caseInstanceId;\n        this.variableName = variableName;\n        this.variableValue = variableValue;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variable name is null\");\n        }\n     \n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n        \n        addVariable(false, caseInstanceId, null, variableName, variableValue, caseInstanceEntity.getTenantId(), \n                cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService());\n        createSetAsyncVariablesJob(caseInstanceEntity, cmmnEngineConfiguration);\n        \n        return null;\n    }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariableAsyncCmd.java#L20-L56","documentation":"Thrown by SetVariableAsyncCmd.execute when the caseInstanceId passed to the async set-variable command is null. Flowable validates required arguments up front and rejects null ids with FlowableIllegalArgumentException rather than doing a DB lookup.","triggerScenarios":"Calling setVariableAsync (or building SetVariableAsyncCmd) without setting caseInstanceId, e.g. from code where the case instance id variable is null or a lookup returned null and wasn't checked.","commonSituations":"A previous query returned null and its result was passed straight through, builder fields forgotten, or an API/REST layer dropped the parameter.","solutions":["Ensure caseInstanceId is populated before calling setVariableAsync","Validate the id string is non-null/non-empty at the call site","Trace where the id comes from; fix the upstream query that returned null"],"exampleFix":"// before\ncmmnRuntimeService.setVariableAsync(caseInstanceId, \"status\", \"done\"); // caseInstanceId may be null\n// after\nObjects.requireNonNull(caseInstanceId, \"caseInstanceId must not be null\");\ncmmnRuntimeService.setVariableAsync(caseInstanceId, \"status\", \"done\");","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null || caseInstanceId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"caseInstanceId must not be null or empty\");\n}","typeGuard":"boolean hasCaseInstanceId(String id) { return id != null && !id.trim().isEmpty(); }","tryCatchPattern":"try {\n    cmmnRuntimeService.setVariableAsync(caseInstanceId, name, value);\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Invalid argument for setVariableAsync: {}\", e.getMessage());\n}","preventionTips":["Capture the returned case instance id at case start and pass it explicitly","Validate ids at service/REST boundaries before invoking engine commands","Avoid nullable id fields in code paths that reach the engine"],"tags":["flowable","cmmn","null-check","validation"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}