diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java index 52fd2ff52..ea6b9d5cc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java @@ -286,37 +286,9 @@ public class ItemOrientedStep extends AbstractStep { // Attempt to flush before the step execution and stream // state are updated - try { - itemHandler.flush(); - } - catch (Error e) { - if (transactionAttribute.rollbackOn(e)) { - throw e; - } - nonRollbackException = e; - } - catch (Exception e) { - if (transactionAttribute.rollbackOn(e)) { - throw e; - } - nonRollbackException = e; - } + itemHandler.flush(); - try { - stream.update(stepExecution.getExecutionContext()); - } - catch (Error e) { - if (transactionAttribute.rollbackOn(e)) { - throw e; - } - nonRollbackException = e; - } - catch (Exception e) { - if (transactionAttribute.rollbackOn(e)) { - throw e; - } - nonRollbackException = e; - } + stream.update(stepExecution.getExecutionContext()); try { getJobRepository().saveOrUpdateExecutionContext(stepExecution); @@ -408,7 +380,22 @@ public class ItemOrientedStep extends AbstractStep { } // check for interruption before each item as well interruptionPolicy.checkInterrupted(execution); - ExitStatus exitStatus = itemHandler.handle(contribution); + ExitStatus exitStatus = ExitStatus.FINISHED; + + try{ + exitStatus = itemHandler.handle(contribution); + } + catch (Error e) { + if (transactionAttribute.rollbackOn(e)) { + throw e; + } + } + catch (Exception e) { + if (transactionAttribute.rollbackOn(e)) { + throw e; + } + } + // check for interruption after each item as well interruptionPolicy.checkInterrupted(execution); return exitStatus; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java index e2f0f92de..779f18113 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java @@ -841,35 +841,6 @@ public class ItemOrientedStepTests extends TestCase { } - public void testNoRollbackOnHandlerException() throws Exception{ - - final RuntimeException exception = new RuntimeException(); - ItemReader itemReader = new AbstractItemReader() { - public Object read() throws Exception { - // Trigger a rollback - throw exception; - } - }; - itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter)); - itemOrientedStep.setTransactionAttribute(new NeverRollbackTransactionAttribute()); - - JobExecution jobExecutionContext = new JobExecution(jobInstance); - StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext); - - stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar"))); - // step.setLastExecution(stepExecution); - - try { - itemOrientedStep.execute(stepExecution); - fail("Expected RuntimeException"); - } - catch (RuntimeException ex) { - assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); - // The original rollback was caused by this one: - assertSame(exception, ex); - } - } - public void testNoRollbackOnFlushException() throws Exception{ final RuntimeException exception = new RuntimeException();