{"record":{"id":"4436c9cfb0524450","repo":"flowable/flowable-engine","slug":"no-case-instance-found-for-id-4436c9","errorCode":null,"errorMessage":"No case instance found for id ","messagePattern":"No case instance found for id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetHistoricStageOverviewCmd.java","lineNumber":62,"sourceCode":"/**\n * @author Tijs Rademakers\n */\npublic class GetHistoricStageOverviewCmd implements Command<List<StageResponse>>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    \n    protected String caseInstanceId;\n\n    public GetHistoricStageOverviewCmd(String caseInstanceId) {\n        this.caseInstanceId = caseInstanceId;\n    }\n\n    @Override\n    public List<StageResponse> execute(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        HistoricCaseInstanceEntity caseInstance = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findById(caseInstanceId);\n        if (caseInstance == null) {\n            throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceId, HistoricCaseInstanceEntity.class);\n        }\n\n        HistoricPlanItemInstanceEntityManager planItemInstanceEntityManager = cmmnEngineConfiguration.getHistoricPlanItemInstanceEntityManager();\n        List<HistoricPlanItemInstance> planItemInstances = planItemInstanceEntityManager.findByCriteria(new HistoricPlanItemInstanceQueryImpl()\n            .planItemInstanceCaseInstanceId(caseInstanceId)\n            .planItemInstanceDefinitionTypes(Arrays.asList(PlanItemDefinitionType.STAGE, PlanItemDefinitionType.MILESTONE))\n            .orderByEndedTime().asc());\n\n        // Filter out the states that shouldn't be returned in the overview\n        planItemInstances.removeIf(planItemInstance -> PlanItemInstanceState.INTERMEDIARY_STATES.contains(planItemInstance.getState()));\n\n        CmmnDeploymentManager deploymentManager = cmmnEngineConfiguration.getDeploymentManager();\n        CaseDefinition caseDefinition = deploymentManager.findDeployedCaseDefinitionById(caseInstance.getCaseDefinitionId());\n        CmmnModel cmmnModel = deploymentManager.resolveCaseDefinition(caseDefinition).getCmmnModel();\n        List<Stage> stages = cmmnModel.getPrimaryCase().getPlanModel().findPlanItemDefinitionsOfType(Stage.class, true);\n        List<Milestone> milestones = cmmnModel.getPrimaryCase().getPlanModel().findPlanItemDefinitionsOfType(Milestone.class, true);\n        \n        List<OverviewElement> overviewElements = new ArrayList<>();","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetHistoricStageOverviewCmd.java#L44-L80","documentation":"GetHistoricStageOverviewCmd.execute looks up the historic case instance via HistoricCaseInstanceEntityManager.findById(caseInstanceId). If none is found it throws FlowableObjectNotFoundException naming the id, because a stage overview can only be built for an existing historic case instance.","triggerScenarios":"Calling the command with a caseInstanceId that does not exist in historic case instance storage: not-yet-completed case (still runtime), deleted history, wrong engine, or a mistyped id.","commonSituations":"Requesting a stage overview before the case finished (data lives in runtime tables until completion), history level configured too low, stale ids after history cleanup jobs.","solutions":["Confirm the case instance is completed/archived (query historic case instance first) and the id is correct.","If the case is still running, use the runtime plan item/stage APIs instead.","Check history cleanup configuration/cleanup jobs have not removed the instance."],"exampleFix":"// before\nList<StageResponse> stages = getStageOverview(caseInstanceId);\n// after\nHistoricCaseInstance hci = cmmnHistoryService.createHistoricCaseInstanceQuery()\n    .caseInstanceId(caseInstanceId).singleResult();\nList<StageResponse> stages = hci != null\n    ? getStageOverview(caseInstanceId)\n    : Collections.emptyList();","handlingStrategy":"try-catch","validationCode":"HistoricCaseInstance c = cmmnHistoryService.createHistoricCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (c == null) { throw new NotFoundException(\"No historic case instance \" + caseInstanceId); }","typeGuard":"boolean historicCaseExists = cmmnHistoryService.createHistoricCaseInstanceQuery().caseInstanceId(id).count() > 0;","tryCatchPattern":"try { return stageOverviewService.getStageOverview(caseInstanceId); } catch (FlowableObjectNotFoundException e) { log.warn(\"Historic case instance not found: {}\", caseInstanceId); return Collections.emptyList(); }","preventionTips":["Only request stage overviews for completed/archived case instances","Use runtime plan item APIs while the case is still active","Account for history cleanup jobs when caching ids"],"tags":["flowable","cmmn","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"}