Skip to content

Commit 7f375c6

Browse files
committed
Fix error propagation from job executions
Before this commit, Spring Batch was catching all Throwable types so they can be available after the job execution through jobExecution.getAllFailureExceptions(). However, this prevents the JVM to crash on any Error like it should (for example like OOM errors [1]), effectively preventing the possibility to generate heap dumps to analyze these kinds of errors. This commit updates the code to catch only exceptions and let errors bubble up to let the JVM handle them as needed. Resolves #808 [1]: https://stackoverflow.com/questions/54811702/spring-batch-doesnt-propagate-errors
1 parent 0125b19 commit 7f375c6

File tree

1 file changed

+5
-11
lines changed
  • spring-batch-core/src/main/java/org/springframework/batch/core/job

1 file changed

+5
-11
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import org.springframework.batch.core.repository.JobRepository;
4545
import org.springframework.batch.core.launch.JobRestartException;
4646
import org.springframework.batch.core.scope.context.JobSynchronizationManager;
47-
import org.springframework.batch.core.step.StepLocator;
48-
import org.springframework.batch.infrastructure.repeat.RepeatException;
4947
import org.springframework.beans.factory.BeanNameAware;
5048
import org.springframework.beans.factory.InitializingBean;
5149
import org.springframework.util.Assert;
@@ -292,15 +290,11 @@ public final void execute(JobExecution execution) throws JobInterruptedException
292290

293291
listener.beforeJob(execution);
294292

295-
try {
296-
doExecute(execution);
297-
if (logger.isDebugEnabled()) {
298-
logger.debug("Job execution complete: " + execution);
299-
}
300-
}
301-
catch (RepeatException e) {
302-
throw e.getCause();
293+
doExecute(execution);
294+
if (logger.isDebugEnabled()) {
295+
logger.debug("Job execution complete: " + execution);
303296
}
297+
304298
}
305299
else {
306300

@@ -326,7 +320,7 @@ public final void execute(JobExecution execution) throws JobInterruptedException
326320
execution.setStatus(BatchStatus.max(BatchStatus.STOPPED, e.getStatus()));
327321
execution.addFailureException(e);
328322
}
329-
catch (Throwable t) {
323+
catch (Exception t) {
330324
logger.error("Encountered fatal error executing job", t);
331325
execution.setExitStatus(getDefaultExitStatusForFailure(t));
332326
execution.setStatus(BatchStatus.FAILED);

0 commit comments

Comments
 (0)