{"record":{"id":"d6240c22c89abf8c","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-d6240c","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/RemoveVariableCmd.java","lineNumber":38,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\n\n/**\n * @author Joram Barrez\n */\npublic class RemoveVariableCmd implements Command<Void> {\n    \n    protected String caseInstanceId;\n    protected String variableName;\n    \n    public RemoveVariableCmd(String caseInstanceId, String variableName) {\n        this.caseInstanceId = caseInstanceId;\n        this.variableName = variableName;\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(\"variableName is null\");\n        }\n     \n        CaseInstanceEntity caseInstanceEntity = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n        caseInstanceEntity.removeVariable(variableName);\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":20,"sourceCodeEnd":54,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/RemoveVariableCmd.java#L20-L54","documentation":"RemoveVariableCmd removes a single variable from a CMMN case instance. It validates its inputs first and throws FlowableIllegalArgumentException when caseInstanceId is null, because removing a variable requires a target case instance.","triggerScenarios":"Passing null as the caseInstanceId argument to the remove-variable command / RuntimeService API, typically when an upstream lookup returned null and the result was forwarded unchecked.","commonSituations":"caseInstance singleResult() returned null (not found) and code did caseInstance.getId() style chains with nullable ids; optional request parameters bound to null in REST controllers.","solutions":["Ensure caseInstanceId is non-null before invoking; fail fast at the caller","Load the case instance first and use the returned entity's id","Add an explicit null guard or Objects.requireNonNull with a clear message","If the id comes from a request, validate it as required input"],"exampleFix":"// before\ncmmnRuntimeService.removeVariable(caseInstanceId, variableName); // caseInstanceId may be null\n// after\nObjects.requireNonNull(caseInstanceId, \"caseInstanceId must not be null\");\ncmmnRuntimeService.removeVariable(caseInstanceId, variableName);","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null) throw new IllegalArgumentException(\"caseInstanceId is required\");","typeGuard":null,"tryCatchPattern":"try { cmmnRuntimeService.removeVariable(id, name); } catch (FlowableIllegalArgumentException e) { log.error(\"Invalid input: {}\", e.getMessage()); }","preventionTips":["Validate required ids at the API boundary","Fail fast on null results from lookups instead of forwarding them","Use Objects.requireNonNull on engine-facing parameters"],"tags":["cmmn","null-argument","variables"],"backgroundTag":"null-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"}