diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index 64b1a8033..2302901c4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -220,6 +220,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw try { // Update the step execution to the latest known value so the listeners can act on it + exitStatus = exitStatus.and(stepExecution.getExitStatus()); stepExecution.setExitStatus(exitStatus); exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution)); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java index 89a969be9..496b259b8 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java @@ -85,6 +85,19 @@ public class TaskletStepExceptionTests { assertEquals(STOPPED.toString(), stepExecution.getExitStatus().getExitCode()); } + @Test + public void testInterruptedWithCustomStatus() throws Exception { + taskletStep.setTasklet(new Tasklet() { + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { + contribution.setExitStatus(new ExitStatus("FUNNY")); + throw new JobInterruptedException("Planned"); + } + }); + taskletStep.execute(stepExecution); + assertEquals(STOPPED, stepExecution.getStatus()); + assertEquals("FUNNY", stepExecution.getExitStatus().getExitCode()); + } + @Test public void testOpenFailure() throws Exception { final RuntimeException exception = new RuntimeException();