{"record":{"id":"bf96aae19264a467","repo":"flowable/flowable-engine","slug":"could-not-find-a-milestone-instance-with-id-mil","errorCode":null,"errorMessage":"Could not find a milestone instance with id '${milestoneInstanceId}'.","messagePattern":"Could not find a milestone instance with id '(.+?)'\\.","errorType":"http","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/milestone/HistoricMilestoneInstanceResource.java","lineNumber":45,"sourceCode":"import io.swagger.annotations.Authorization;\n\n/**\n * @author Tijs Rademakers\n * @author Dennis Federico\n */\n@RestController\n@Api(tags = {\"History Milestone\"}, authorizations = {@Authorization(value = \"basicAuth\")})\npublic class HistoricMilestoneInstanceResource extends HistoricMilestoneInstanceBaseResource {\n\n    @ApiOperation(value = \"Get a historic milestone instance by id\", tags = {\"History Milestone\"}, nickname = \"getHistoricMilestoneInstanceById\")\n    @ApiResponses(value = {\n            @ApiResponse(code = 200, message = \"Indicates that the historic milestone instances could be found.\"),\n            @ApiResponse(code = 404, message = \"Indicates that the historic milestone instances could not be found.\")})\n    @GetMapping(value = \"/cmmn-history/historic-milestone-instances/{milestoneInstanceId}\", produces = \"application/json\")\n    public HistoricMilestoneInstanceResponse getMilestoneInstance(@ApiParam(name = \"milestoneInstanceId\") @PathVariable String milestoneInstanceId) {\n        HistoricMilestoneInstance milestoneInstance = historyService.createHistoricMilestoneInstanceQuery().milestoneInstanceId(milestoneInstanceId).singleResult();\n        if (milestoneInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Could not find a milestone instance with id '\" + milestoneInstanceId + \"'.\", HistoricMilestoneInstance.class);\n        }\n        \n        if (restApiInterceptor != null) {\n            restApiInterceptor.accessHistoryMilestoneInfoById(milestoneInstance);\n        }\n        \n        return restResponseFactory.createHistoricMilestoneInstanceResponse(milestoneInstance);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":55,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/milestone/HistoricMilestoneInstanceResource.java#L27-L55","documentation":"FlowableObjectNotFoundException raised when no historic milestone instance exists with the given milestoneInstanceId. The REST endpoint queries cmmn-history/historic-milestone-instances/{id} and throws a 404-equivalent when singleResult() returns null. The missing type is HistoricMilestoneInstance.","triggerScenarios":"GET /cmmn-history/historic-milestone-instances/{milestoneInstanceId} with an id that does not match any historic milestone instance row (already purged, never existed, or wrong engine/datasource).","commonSituations":"History cleanup job removed old milestone instances; caller stored ids from a different database/tenant; milestone never completed so no historic record was written; history level set below the required level.","solutions":["Confirm the milestoneInstanceId is correct (check for typos or ids from another environment).","Catch FlowableObjectNotFoundException and map it to HTTP 404 in your REST error handler.","Check history cleanup settings - historic instances may have been removed by the cleaner.","Verify the CMMN history level retains milestone instances.","Query the list endpoint with filters to see which milestone instance ids actually exist."],"exampleFix":"// before\nHistoricMilestoneInstanceResponse r = client.getMilestone(id);\n// after\ntry {\n    HistoricMilestoneInstanceResponse r = client.getMilestone(id);\n} catch (FlowableObjectNotFoundException e) {\n    return ResponseEntity.notFound().build();\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    HistoricMilestoneInstanceResponse m = getMilestone(id);\n} catch (FlowableObjectNotFoundException e) {\n    return ResponseEntity.status(HttpStatus.NOT_FOUND).body(\"Milestone not found\");\n}","preventionTips":["Treat any singleResult-by-id REST lookup as optional; always handle 404.","Track ids as opaque strings, never reconstruct them.","Be aware of history cleanup retention windows.","Confirm ids came from the same engine/tenant database."],"tags":["flowable","rest","history","not-found"],"backgroundTag":"resource-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"}