diff --git a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleExitCodeExceptionClassifier.java b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleExitCodeExceptionClassifier.java index 13a3c2ed4..d2b3f954c 100644 --- a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleExitCodeExceptionClassifier.java +++ b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleExitCodeExceptionClassifier.java @@ -20,47 +20,61 @@ import org.springframework.batch.core.executor.StepInterruptedException; import org.springframework.batch.repeat.ExitStatus; /** - *

Simple implementation of {@link ExitCodeExceptionClassifier} that returns basic - * String exit codes, and defaults to the class name of the throwable - * for the message. Most users will want to write their own implementation - * that creates more specific exit codes for different exception types.

+ *

+ * Simple implementation of {@link ExitCodeExceptionClassifier} that returns + * basic String exit codes, and defaults to the class name of the throwable for + * the message. Most users will want to write their own implementation that + * creates more specific exit codes for different exception types. + *

* * @author Lucas Ward - * + * */ public class SimpleExitCodeExceptionClassifier implements ExitCodeExceptionClassifier { - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.springframework.batch.core.executor.ExitCodeExceptionClassifier#classifyForExitCode(java.lang.Throwable) */ public ExitStatus classifyForExitCode(Throwable throwable) { - return (ExitStatus)classify(throwable); + return (ExitStatus) classify(throwable); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.springframework.batch.common.ExceptionClassifier#classify(java.lang.Throwable) */ public Object classify(Throwable throwable) { - + ExitStatus exitStatus = ExitStatus.FAILED; - - if(throwable instanceof StepInterruptedException){ - exitStatus = new ExitStatus(false, STEP_INTERRUPTED, StepInterruptedException.class.getName()); + + if (throwable instanceof StepInterruptedException) { + exitStatus = new ExitStatus(false, STEP_INTERRUPTED, + StepInterruptedException.class.getName()); + } else { + String message = ""; + if (throwable!=null) { + message = throwable.getClass().getName(); + if (throwable.getMessage()!=null) { + message += ": " + throwable.getMessage(); + } + } + exitStatus = new ExitStatus(false, FATAL_EXCEPTION, message); } - else{ - exitStatus = new ExitStatus(false, - FATAL_EXCEPTION, throwable == null ? "" : throwable.getClass().getName()); - } - + return exitStatus; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.springframework.batch.common.ExceptionClassifier#getDefault() */ public Object getDefault() { - //return without message since we don't know what the exception is + // return without message since we don't know what the exception is return new ExitStatus(false, FATAL_EXCEPTION); } diff --git a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java index 86d97913e..f4ee38938 100644 --- a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java +++ b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java @@ -254,7 +254,6 @@ public class SimpleStepExecutor implements StepExecutor { //classify exception so an exit code can be stored. status = exceptionClassifier.classifyForExitCode(e); - stepExecution.setException(e); if (e.getCause() instanceof StepInterruptedException) { updateStatus(stepExecution, BatchStatus.STOPPED); throw (StepInterruptedException) e.getCause(); diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java index c6a561e72..9c8e95185 100644 --- a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java @@ -238,10 +238,10 @@ public class DefaultStepExecutorTests extends TestCase { try { stepExecutor.process(stepConfiguration, stepExecution); } catch (Exception ex) { - assertEquals(step.getStepExecution().getExitStatus(), - new ExitStatus(false, - ExitCodeExceptionClassifier.FATAL_EXCEPTION, - "java.lang.RuntimeException")); + assertEquals(new ExitStatus(false, + ExitCodeExceptionClassifier.FATAL_EXCEPTION, + "java.lang.RuntimeException"), step.getStepExecution() + .getExitStatus()); } } @@ -385,8 +385,7 @@ public class DefaultStepExecutorTests extends TestCase { * StepInterruptionPolicy interruptionPolicy = new StepInterruptionPolicy(){ * * public void checkInterrupted(RepeatContext context) throws - * StepInterruptedException { throw new StepInterruptedException(""); } - * }; + * StepInterruptedException { throw new StepInterruptedException(""); } }; * * stepExecutor.setInterruptionPolicy(interruptionPolicy); * @@ -397,8 +396,7 @@ public class DefaultStepExecutorTests extends TestCase { * * if(counter == 1){ throw new StepInterruptedException(""); } * - * return ExitStatus.CONTINUABLE; } - * }; + * return ExitStatus.CONTINUABLE; } }; * * StepInstance step = new StepInstance(new Long(1)); * stepConfiguration.setTasklet(tasklet); JobExecutionContext