SimpleStepExecutionSplitter does not restart COMPLETED partitions even when allowStartIfComplete=true (original) (raw)
Bug Description
In SimpleStepExecutionSplitter.split(), partitions with COMPLETED status are always skipped, even when allowStartIfComplete=true is set or within the same JobExecution.
Affected Versions
- Spring Batch 6.0.2 (5.x is not affected)
Problem Code
// SimpleStepExecutionSplitter.java:146-153 else { // restart if (lastStepExecution.getStatus() != BatchStatus.COMPLETED // ← Problem! && shouldStart(allowStartIfComplete, stepExecution, lastStepExecution)) { // ... } }
The != BatchStatus.COMPLETED condition is evaluated before shouldStart() is called, so shouldStart() is never invoked for COMPLETED partitions.
In contrast, regular Steps (SimpleStepHandler) call shouldStart() first, which works correctly.
Proposed Fix
// Before (bug) if (lastStepExecution.getStatus() != BatchStatus.COMPLETED && shouldStart(...)) {
// After (fix) if (shouldStart(...)) {
Remove the redundant condition since shouldStart() already handles COMPLETED status correctly.
Test Cases
| Scenario | Expected | Actual |
|---|---|---|
| allowStartIfComplete=true + COMPLETED partitions | restart | skipped (bug) |
| Same JobExecution + COMPLETED partitions | restart | skipped (bug) |
| Mixed status (COMPLETED + FAILED) with allowStartIfComplete=true | 2 partitions | 1 partition (bug) |
Related Information
| Item | Details |
|---|---|
| Introduced in commit | 90d8959 |
| Affected versions | 6.0.2 |