{"record":{"id":"ddbfcec3a4041b4c","repo":"flowable/flowable-engine","slug":"cannot-find-task-with-id-taskid-ddbfce","errorCode":null,"errorMessage":"Cannot find task with id ${taskId}","messagePattern":"Cannot find task with id (.+?)","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/CreateAttachmentCmd.java","lineNumber":117,"sourceCode":"            commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(\n                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, \n                            attachment, processInstanceId, processInstanceId, processDefinitionId),\n                    EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);\n            commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(\n                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, \n                            attachment, processInstanceId, processInstanceId, processDefinitionId),\n                    EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);\n        }\n\n        return attachment;\n    }\n\n    private void verifyParameters(CommandContext commandContext) {\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(\"It is not allowed to add an attachment to a suspended task\");\n            }\n        }\n\n        if (processInstanceId != null) {\n            ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n            if (execution == null) {\n                throw new ActivitiObjectNotFoundException(\"Process instance \" + processInstanceId + \" doesn't exist\", ProcessInstance.class);\n            }\n\n            if (execution.isSuspended()) {\n                throw new ActivitiException(\"It is not allowed to add an attachment to a suspended process instance\");\n            }\n        }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/CreateAttachmentCmd.java#L99-L135","documentation":"CreateAttachmentCmd verifies that, when a taskId is supplied, a task with that id exists; it throws ActivitiObjectNotFoundException with Task.class when findTaskById returns null. Attachments are bound to existing tasks, so a dangling id is rejected.","triggerScenarios":"taskService.createAttachment(attachmentType, taskId, processInstanceId, ...) with a taskId that does not exist (deleted, completed-and-cleaned, wrong db, or typo).","commonSituations":"Storing a task id in an external form/URL and attaching after the task was completed; using an id from another environment or schema; string concatenation typos.","solutions":["Verify the task exists (taskService.createTaskQuery().taskId(id).singleResult()) before attaching","Correct the taskId value","Confirm you are connected to the same database where the task lives"],"exampleFix":"// before\ntaskService.createAttachment(\"text\", badTaskId, null, \"name\", \"desc\", content);\n// after\nif (taskService.createTaskQuery().taskId(taskId).singleResult() != null) {\n    taskService.createAttachment(\"text\", taskId, null, \"name\", \"desc\", content);\n}","handlingStrategy":"validation","validationCode":"boolean taskExists = taskId == null || taskService.createTaskQuery().taskId(taskId).count() > 0;","typeGuard":null,"tryCatchPattern":"try { taskService.createAttachment(type, taskId, procInstId, name, desc, stream); } catch (ActivitiObjectNotFoundException e) { log.warn(\"Target task/process missing: {}\", e.getMessage()); }","preventionTips":["Only attach using ids obtained from live queries, not cached values","Clean up attachment flows when tasks complete","Run attachment code against the same datasource/environment"],"tags":["not-found","task","attachment"],"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-18T11:17:12.947Z"}