{"record":{"id":"61c84adc0262e9da","repo":"flowable/flowable-engine","slug":"execution-processinstanceid-doesn-t-exist-61c84a","errorCode":null,"errorMessage":"execution ${processInstanceId} doesn't exist","messagePattern":"execution (.+?) doesn't exist","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java","lineNumber":72,"sourceCode":"\n        // Validate task\n        if (taskId != null) {\n            TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);\n\n            if (task == null) {\n                throw new ActivitiObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n            }\n\n            if (task.isSuspended()) {\n                throw new ActivitiException(getSuspendedTaskException());\n            }\n        }\n\n        if (processInstanceId != null) {\n            ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n            if (execution == null) {\n                throw new ActivitiObjectNotFoundException(\"execution \" + processInstanceId + \" doesn't exist\", Execution.class);\n            }\n\n            if (execution.isSuspended()) {\n                throw new ActivitiException(getSuspendedExceptionMessage());\n            }\n        }\n\n        String userId = Authentication.getAuthenticatedUserId();\n        CommentEntity comment = new CommentEntity();\n        comment.setUserId(userId);\n        comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);\n        comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());\n        comment.setTaskId(taskId);\n        comment.setProcessInstanceId(processInstanceId);\n        comment.setAction(Event.ACTION_ADD_COMMENT);\n\n        String eventMessage = message.replaceAll(\"\\\\s+\", \" \");\n        if (eventMessage.length() > 163) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java#L54-L90","documentation":"AddCommentCmd.execute validates an optional processInstanceId by looking up the execution and throws ActivitiObjectNotFoundException when no execution with that id exists. A comment can reference a process instance, but the referenced instance must exist at comment time.","triggerScenarios":"Calling TaskService.addComment(taskId, processInstanceId, message) or addComment(null, processInstanceId, message) with a processInstanceId that does not exist, already ended, or is mistyped.","commonSituations":"Commenting against a completed instance whose runtime execution row is gone (use history instead); id taken from a business key rather than the runtime id; environment/database mismatch.","solutions":["Check existence first: runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() > 0.","Use the runtime ProcessInstance.getId(), not the business key.","If the instance is finished, add the comment to the related historical data via HistoryService instead of the runtime comment API.","Confirm arguments are not swapped: addComment(taskId, processInstanceId, message)."],"exampleFix":"// before\ntaskService.addComment(null, instanceId, \"note\");\n// after\nif (runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).count() > 0) {\n    taskService.addComment(null, instanceId, \"note\");\n}","handlingStrategy":"validation","validationCode":"boolean exists = runtimeService.createProcessInstanceQuery()\n    .processInstanceId(processInstanceId).count() > 0;\nif (!exists) { throw new IllegalStateException(\"Process instance \" + processInstanceId + \" not running\"); }","typeGuard":null,"tryCatchPattern":"try {\n    taskService.addComment(null, processInstanceId, message);\n} catch (ActivitiObjectNotFoundException e) {\n    if (e.getMessage().startsWith(\"execution \")) {\n        logger.warn(\"Instance {} finished; store comment via history\", processInstanceId);\n    } else { throw e; }\n}","preventionTips":["Validate the instance id against a runtime query first","Do not pass business keys where runtime instance ids are expected","Route comments for finished instances to history services"],"tags":["process-instance","not-found","comment","activiti"],"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-14T11:17:12.474Z"}