flowable/flowable-engine · error · ActivitiObjectNotFoundException

No historic task exists with the given id:

Error message

No historic task exists with the given id: 

What it means

When querying historic identity links by taskId, the command first loads the historic task instance. If no historic task exists with that id, it throws ActivitiObjectNotFoundException naming the id and HistoricTaskInstance.class.

Source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetHistoricIdentityLinksForTaskCmd.java:61

    }

    @Override
    public List<HistoricIdentityLink> execute(CommandContext commandContext) {
        if (taskId != null) {
            return getLinksForTask(commandContext);
        } else {
            return getLinksForProcessInstance(commandContext);
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected List<HistoricIdentityLink> getLinksForTask(CommandContext commandContext) {
        HistoricTaskInstanceEntity task = commandContext
                .getHistoricTaskInstanceEntityManager()
                .findHistoricTaskInstanceById(taskId);

        if (task == null) {
            throw new ActivitiObjectNotFoundException("No historic task exists with the given id: " + taskId, HistoricTaskInstance.class);
        }

        List<HistoricIdentityLink> identityLinks = (List) commandContext
                .getHistoricIdentityLinkEntityManager()
                .findHistoricIdentityLinksByTaskId(taskId);

        // Similar to GetIdentityLinksForTask, return assignee and owner as identity link
        if (task.getAssignee() != null) {
            HistoricIdentityLinkEntity identityLink = new HistoricIdentityLinkEntity();
            identityLink.setUserId(task.getAssignee());
            identityLink.setTaskId(task.getId());
            identityLink.setType(IdentityLinkType.ASSIGNEE);
            identityLinks.add(identityLink);
        }
        if (task.getOwner() != null) {
            HistoricIdentityLinkEntity identityLink = new HistoricIdentityLinkEntity();
            identityLink.setTaskId(task.getId());
            identityLink.setUserId(task.getOwner());

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the taskId corresponds to an existing historic task via historyService.createHistoricTaskInstanceQuery().taskId(id).count()
  2. Raise the history level (e.g. 'audit' or 'full') in process engine configuration so historic tasks are recorded
  3. Catch ActivitiObjectNotFoundException and treat it as 'no history for this task'
  4. Confirm the task actually finished or has history rows (ACT_HI_TASKINST) in the database

Example fix

// before
List<HistoricIdentityLink> links = historyService.getHistoricIdentityLinksForTask(taskId);
// after
long n = historyService.createHistoricTaskInstanceQuery().taskId(taskId).count();
if (n == 0) { /* no historic task: skip or warn */ }
else { List<HistoricIdentityLink> links = ...; }
Defensive patterns

Strategy: try-catch

Validate before calling

long count = historyService.createHistoricTaskInstanceQuery().taskId(taskId).count();
boolean exists = count > 0;

Type guard

boolean historicTaskExists(String taskId) {
    return taskId != null && historyService.createHistoricTaskInstanceQuery().taskId(taskId).count() > 0;
}

Try / catch

try {
    List<HistoricIdentityLink> links = ...;
} catch (ActivitiObjectNotFoundException e) {
    // no historic task for this id: return empty / 404
}

Prevention

When it happens

Trigger: Calling the identity-links API with a taskId that does not exist in the historic tables — e.g. a task that never completed/started within history retention, a deleted history level ('none'/'activity'), or a mistyped/garbage-collected id.

Common situations: History level configured too low so tasks are not persisted; querying a running (not yet historic) task's id; stale ids from a cleaned-up database; typo between runtime task id and historic task id (they match, but only after history is written).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/d27f1e3dea47f1b7. Report an issue: GitHub.