{"record":{"id":"56c1b8ac3e5f51a3","repo":"flowable/flowable-engine","slug":"no-historic-case-instance-found-with-id","errorCode":null,"errorMessage":"No historic case instance found with id: ","messagePattern":"No historic case instance found with id: ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstanceCmd.java","lineNumber":51,"sourceCode":"    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());\n\n        return null;\n    }\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstanceCmd.java#L33-L68","documentation":"After the null check, the command loads the historic case instance by id via HistoricCaseInstanceEntityManager.findById. If none is found it throws FlowableObjectNotFoundException with type HistoricCaseInstance. The id never existed in history, history was not recorded (history level too low), or the record was already deleted.","triggerScenarios":"Calling CmmnHistoryService.deleteHistoricCaseInstance(id) with an unknown id, an id from another engine/database, or after the history row was already purged by cleanup.","commonSituations":"History level set to NONE/ACTIVITY so case history is never written; retention jobs deleting rows before app code; cross-environment data (test id used against prod).","solutions":["Verify existence with historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).singleResult() before deleting","Ensure the engine history level records case instances (configure cmmn history level to AUDIT/FULL)","Make deletion idempotent: catch FlowableObjectNotFoundException and log instead of failing","Confirm the id is from the same environment/database"],"exampleFix":"// before\nhistoryService.deleteHistoricCaseInstance(caseId);\n// after\nHistoricCaseInstance hci = historyService.createHistoricCaseInstanceQuery().caseInstanceId(caseId).singleResult();\nif (hci != null) {\n    historyService.deleteHistoricCaseInstance(caseId);\n}","handlingStrategy":"validation","validationCode":"HistoricCaseInstance hci = historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).singleResult();\nif (hci == null) { log.info(\"no historic case instance {}\", id); return; }","typeGuard":null,"tryCatchPattern":"try { historyService.deleteHistoricCaseInstance(id); }\ncatch (FlowableObjectNotFoundException e) { if (e.getObjectClass() != null && HistoricCaseInstance.class.equals(e.getObjectClass())) { log.info(\"already deleted: {}\", id); } else throw e; }","preventionTips":["Confirm history level records case instances (AUDIT or higher)","Treat not-found as idempotent success in cleanup jobs","Do not cross-use ids between environments/databases"],"tags":["cmmn","history","resource-not-found","historic-case-instance"],"backgroundTag":"record-not-found","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"}