Repository navigation
Description
Describe the bug
When a job (e.g. a timer intermediate catch event inside an embedded subprocess) is executed while
another transaction deletes or terminates the process instance, the engine fails with a
NullPointerException in ExecutionEntity.ensureExecutionTreeInitialized instead of an
OptimisticLockingException.
JobEntity.execute loads only the job's execution. When the handler later calls
execution.getProcessInstance() (e.g. from PvmExecutionImpl.getDelayedEvents()), the execution
tree is loaded with findExecutionsByProcessInstanceId. If the process instance was deleted and
committed in between, the list is empty, procInstance stays null and
procInstance.restoreProcessInstance(...) throws.
Because the exception is not an OptimisticLockingException, JobRetryCmd.shouldDecrementRetriesFor
decrements the retries and an incident is created after the retries are exhausted, although there
is nothing left to do: the process instance is gone. The same race on an INSERT is already mapped
to an OptimisticLockingException via enableOptimisticLockingOnForeignKeyViolation.
To Reproduce
- Deploy a process with a timer intermediate catch event inside an embedded subprocess (so the
timer's execution is not the process instance execution). - Start an instance and run a command that loads the timer's execution but not yet the execution
tree (e.g. aControllableCommandthat callsfindExecutionById, syncs, then
execution.getProcessInstance()). - Delete the process instance from another transaction.
- Continue the first command.
Observed: NullPointerException: Cannot invoke "ExecutionEntity.restoreProcessInstance(...)" because "procInstance" is null (logged as ENGINE-16004 when the job handler fails, or ENGINE-20009
when a call activity completes).
Expected behavior
An OptimisticLockingException, so that the job executor retries without decrementing the retries
and then skips the job that no longer exists.
Additional context
- Observed with Operaton 2.1.1; the code is unchanged on
main. - Database-independent: it depends only on when the concurrent deletion becomes visible
(READ COMMITTED). Reproducible with H2 in the engine test suite.
Stack trace (engine frames, Operaton 2.1.1):
ENGINE-16004 Exception while closing command context: Cannot invoke
"org.operaton.bpm.engine.impl.persistence.entity.ExecutionEntity.restoreProcessInstance(...)"
because "procInstance" is null
java.lang.NullPointerException: ...
at org.operaton.bpm.engine.impl.persistence.entity.ExecutionEntity.ensureExecutionTreeInitialized(ExecutionEntity.java:1313)
at org.operaton.bpm.engine.impl.persistence.entity.ExecutionEntity.ensureProcessInstanceInitialized(ExecutionEntity.java:805)
at org.operaton.bpm.engine.impl.persistence.entity.ExecutionEntity.getProcessInstance(ExecutionEntity.java:794)
at org.operaton.bpm.engine.impl.persistence.entity.ExecutionEntity.getProcessInstance(ExecutionEntity.java:97)
at org.operaton.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.getDelayedEvents(PvmExecutionImpl.java:1984)
at org.operaton.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.dispatchDelayedEventsAndPerformOperation(PvmExecutionImpl.java:2021)
at org.operaton.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.dispatchDelayedEventsAndPerformOperation(PvmExecutionImpl.java:2006)
at org.operaton.bpm.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:55)
at org.operaton.bpm.engine.impl.bpmn.behavior.IntermediateCatchEventActivityBehavior.signal(IntermediateCatchEventActivityBehavior.java:51)
at org.operaton.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.signal(PvmExecutionImpl.java:762)
at org.operaton.bpm.engine.impl.jobexecutor.TimerCatchIntermediateEventJobHandler.execute(TimerCatchIntermediateEventJobHandler.java:46)
at org.operaton.bpm.engine.impl.jobexecutor.TimerCatchIntermediateEventJobHandler.execute(TimerCatchIntermediateEventJobHandler.java:27)
at org.operaton.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:123)
at org.operaton.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:106)
at org.operaton.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:41)
at org.operaton.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:29)
at org.operaton.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
...
at org.operaton.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:62)
at org.operaton.bpm.engine.impl.ManagementServiceImpl.executeJob(ManagementServiceImpl.java:124)
Proposed fix
Throw an OptimisticLockingException in ensureExecutionTreeInitialized when no process instance
execution is found. I'm working on this and will open a pull request with a concurrency test.
Activity
shardtVLH commentedon Oct 30, 2026
I'm working on this and will open a pull request with a fix and a concurrency test shortly.
github-actions commentedon Oct 30, 2026
Hey @shardtVLH! 🎉
Thanks for opening your first issue. We really appreciate your interest and contribution. 🙌
👉 Before moving forward, please make sure to check out our Contributing Guidelines and the Code of Conduct. This helps us keep everything clear and consistent.
If you enjoy this project, consider giving it a star ⭐️ — we’d really appreciate that.
Looking forward to your input! 🚀
fix(engine): avoid NPE when process instance is deleted concurrently
fix(engine): handle deleted process instance without tree prefetch