{"record":{"id":"47a208c1f08d834c","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-47a208","errorCode":null,"errorMessage":"caseInstanceId is null","messagePattern":"caseInstanceId is null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstanceCmd.java","lineNumber":44,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\n\n/**\n * @author Tijs Rademakers\n */\npublic class DeleteHistoricCaseInstanceCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    \n    protected String caseInstanceId;\n\n    public DeleteHistoricCaseInstanceCmd(String caseInstanceId) {\n        this.caseInstanceId = caseInstanceId;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n        // Check if case instance is still running\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        HistoricCaseInstanceEntity instance = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findById(caseInstanceId);\n\n        if (instance == null) {\n            throw new FlowableObjectNotFoundException(\"No historic case instance found with id: \" + caseInstanceId, HistoricCaseInstance.class);\n        }\n        if (instance.isDeleted()) {\n            return null;\n        }\n\n\n        if (instance.getEndTime() == null) {\n            throw new FlowableException(\"Case instance is still running, cannot delete \" + instance);\n        }\n\n        cmmnEngineConfiguration.getCmmnHistoryManager().recordHistoricCaseInstanceDeleted(caseInstanceId, instance.getTenantId());","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstanceCmd.java#L26-L62","documentation":"DeleteHistoricCaseInstanceCmd first validates that a caseInstanceId was supplied; a null value throws FlowableIllegalArgumentException(\"caseInstanceId is null\"). The command exists to remove a historic case instance record, so an id is mandatory before any history lookup.","triggerScenarios":"Calling CmmnHistoryService.deleteHistoricCaseInstance(null), e.g. when the id was read from an optional field or a query result that was empty.","commonSituations":"Iterating results where some entities expose null ids; unboxing from an Optional/getter chain returning null; batch cleanup scripts with unfiltered input.","solutions":["Null-check (and emptiness-check) caseInstanceId before invoking the history service","Fix the upstream source returning null ids (query result handling, entity mapping)","Skip records without an id instead of calling the delete API for them"],"exampleFix":"// before\nhistoryService.deleteHistoricCaseInstance(caseInstance.getId());\n// after\nif (caseInstance != null && caseInstance.getId() != null) {\n    historyService.deleteHistoricCaseInstance(caseInstance.getId());\n}","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null || caseInstanceId.isEmpty()) { throw new IllegalArgumentException(\"caseInstanceId required\"); }\nhistoryService.deleteHistoricCaseInstance(caseInstanceId);","typeGuard":"boolean hasId(CaseInstance ci) { return ci != null && ci.getId() != null && !ci.getId().isEmpty(); }","tryCatchPattern":"try { historyService.deleteHistoricCaseInstance(caseId); }\ncatch (FlowableIllegalArgumentException e) { if (\"caseInstanceId is null\".equals(e.getMessage())) { log.warn(\"skipped delete: null id\"); } else throw e; }","preventionTips":["Null-check ids pulled from optional fields before deleting","Skip entities without ids in batch cleanup loops","Prefer querying historic instances first and using their ids"],"tags":["cmmn","history","null-argument","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"}