diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java index 4d72ada7b..3a30d706f 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java @@ -328,12 +328,20 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { fatalException.setException(e); stepExecution.setStatus(BatchStatus.UNKNOWN); } - if (t instanceof RuntimeException) { - throw (RuntimeException) t; + + if(itemSkipPolicy.shouldFail(t)){ + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + else { + throw new RuntimeException(t); + } } - else { - throw new RuntimeException(t); + else{ + logger.error("Exception should not cause step to fail", t); } + + result = ExitStatus.CONTINUABLE; } // Check for interruption after transaction as well, so that diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/AlwaysSkipItemSkipPolicy.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/AlwaysSkipItemSkipPolicy.java index cea764c8b..1d4ff0797 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/AlwaysSkipItemSkipPolicy.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/AlwaysSkipItemSkipPolicy.java @@ -29,4 +29,8 @@ public class AlwaysSkipItemSkipPolicy implements ItemSkipPolicy { public boolean shouldSkip(Exception ex, int skipCount) { return true; } + + public boolean shouldFail(Throwable t) { + return true; + } } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/LimitCheckingItemSkipPolicy.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/LimitCheckingItemSkipPolicy.java index 9d8f2a2bb..b39ecb554 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/LimitCheckingItemSkipPolicy.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/LimitCheckingItemSkipPolicy.java @@ -57,6 +57,7 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy { private final int skipLimit; private ExceptionClassifier exceptionClassifier; + private List failurePreventingExceptions = new ArrayList(); public LimitCheckingItemSkipPolicy(int skipLimit) { this(skipLimit, new ArrayList(0)); @@ -95,5 +96,22 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy { return false; } } + + public boolean shouldFail(Throwable t) { + if(failurePreventingExceptions.contains(t)){ + return false; + } + else{ + return true; + } + } + /** + * Set the list of exceptions that will prevent step execution from failing. + * + * @param failurePreventingExceptions + */ + public void setFailurePreventingExceptions(List failurePreventingExceptions) { + this.failurePreventingExceptions = failurePreventingExceptions; + } } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/NeverSkipItemSkipPolicy.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/NeverSkipItemSkipPolicy.java index fb0fd31ee..77b73ad9e 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/NeverSkipItemSkipPolicy.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/support/NeverSkipItemSkipPolicy.java @@ -29,5 +29,7 @@ public class NeverSkipItemSkipPolicy implements ItemSkipPolicy{ return false; } - + public boolean shouldFail(Throwable t) { + return true; + } }