{"record":{"id":"ce1c68e1e45f78e4","repo":"flowable/flowable-engine","slug":"could-not-find-a-case-instance-with-id-caseinst","errorCode":null,"errorMessage":"Could not find a case instance with id '${caseInstanceId}'.","messagePattern":"Could not find a case instance with id '(.+?)'\\.","errorType":"http","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"warning","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/caze/HistoricCaseInstanceBaseResource.java","lineNumber":302,"sourceCode":"        }\n        \n        return responseList;\n    }\n    \n    protected HistoricCaseInstance getHistoricCaseInstanceFromRequest(String caseInstanceId) {\n        HistoricCaseInstance caseInstance = getHistoricCaseInstanceFromRequestWithoutAccessCheck(caseInstanceId);\n\n        if (restApiInterceptor != null) {\n            restApiInterceptor.accessHistoryCaseInfoById(caseInstance);\n        }\n        \n        return caseInstance;\n    }\n\n    protected HistoricCaseInstance getHistoricCaseInstanceFromRequestWithoutAccessCheck(String caseInstanceId) {\n        HistoricCaseInstance caseInstance = historyService.createHistoricCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\n        if (caseInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Could not find a case instance with id '\" + caseInstanceId + \"'.\", HistoricCaseInstance.class);\n        }\n\n        return caseInstance;\n    }\n\n    protected void addVariables(HistoricCaseInstanceQuery caseInstanceQuery, List<QueryVariable> variables) {\n        for (QueryVariable variable : variables) {\n            if (variable.getVariableOperation() == null) {\n                throw new FlowableIllegalArgumentException(\"Variable operation is missing for variable: \" + variable.getName());\n            }\n            if (variable.getVariableOperation() != QueryVariableOperation.EXISTS && variable.getVariableOperation() != QueryVariableOperation.NOT_EXISTS) {\n                if (variable.getValue() == null) {\n                    throw new FlowableIllegalArgumentException(\"Variable value is missing for variable: \" + variable.getName());\n                }\n            }\n\n            boolean nameLess = variable.getName() == null;\n","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/caze/HistoricCaseInstanceBaseResource.java#L284-L320","documentation":"FlowableObjectNotFoundException thrown when a historic case instance query by id returns no result. The REST layer converts a null singleResult() into a 404-style error because the requested historic case instance does not exist (or is not visible to the caller's history level).","triggerScenarios":"GET on a historic case instance REST endpoint with a caseInstanceId that does not match any row in ACT_HI_CASEINST (wrong id, typo, purged history, or history level never recorded the case).","commonSituations":"Client caches case instance ids after history cleanup jobs ran; querying a runtime case id before completion when history level is 'none' or 'activity'; id taken from a different engine/database.","solutions":["Verify the caseInstanceId exists: query ACT_HI_CASEINST (SELECT * FROM ACT_HI_CASEINST WHERE ID_ = ?) or call historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).count() first","Check the engine's history level (process/history config) is high enough to record case instances","Confirm the REST call targets the same database/schema the case was executed in","Handle the 404 client-side and treat the id as expired; re-fetch the id from the case list endpoint"],"exampleFix":"// before\nHistoricCaseInstance ci = historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).singleResult(); // null -> REST 404\n// after\nlong n = historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).count();\nif (n == 0) { throw new MyNotFoundException(\"Historic case \" + id + \" not found\"); }","handlingStrategy":"validation","validationCode":"long n = historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).count();\nif (n == 0) throw new IllegalArgumentException(\"Historic case instance not found: \" + id);","typeGuard":"boolean historicCaseExists(String id) {\n  return historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).count() > 0;\n}","tryCatchPattern":"try { ... } catch (FlowableObjectNotFoundException e) {\n  log.warn(\"Historic case instance {} not found\", id);\n  return Optional.empty();\n}","preventionTips":["Pre-check existence with a count query before fetching","Account for history cleanup jobs when caching ids","Verify engine history level records case instances"],"tags":["rest-api","flowable","not-found","history"],"backgroundTag":"entity-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"}