The default behavior in the engine is that whenever a job fails, the retry of the failing job is decremented. When the job retry is set to 0, then a new incident is created. The decrement of the job retry and creation of the incident happens in a transaction listener which is registered on the transaction state ROLLED_BACK.
If the creation of the incident fails, the transaction is also rolled back and the job retry property stays by 1. This could lead to a kind of a loop, so that the execution of job fails and the job retries cannot be decremented in a separate transaction because of the failing incident creation.
This can happen for example here: https://github.com/camunda/camunda-bpm-platform/blob/master/engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/IncidentEntity.java#L140
For some reason the executionId is not null, but the respective fetched execution is null, so that newIncident.setExecution(execution) will fail with a NullPointerException.
- make the creation of an incident null safe