Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error message when an exception is thrown in JobExecutionListener#afterJob [BATCH-2782] #822

spring-issuemaster opened this issue Jan 4, 2019 · 1 comment


Copy link

@spring-issuemaster spring-issuemaster commented Jan 4, 2019

Mahmoud Ben Hassine opened BATCH-2782 and commented

When a runtime exception is thrown in org.springframework.batch.core.JobExecutionListener#afterJob, the error message in the log is:

Exception encountered in afterStep callback

while it should be

Exception encountered in afterJob callback

Here is an example:

//create job repository
JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject();

// create job
AbstractJob job = new AbstractJob("myJob") {

	public Step getStep(String stepName) {
		return null;

	public Collection<String> getStepNames() {
		return Collections.emptyList();

	protected void doExecute(JobExecution jobExecution) {
		System.out.println("executing job");

job.registerJobExecutionListener(new JobExecutionListener() {
	public void beforeJob(JobExecution jobExecution) {
		System.out.println("before job");

	public void afterJob(JobExecution jobExecution) {
		System.out.println("after job");
		throw new RuntimeException("Boom!");

// execute job
JobExecution jobExecution = jobRepository.createJobExecution("myJob", new JobParameters());

// prints:
// before job
// executing job
// after job
// Exception encountered in afterStep callback

The job has no steps (which is completely valid) and the error message is obviously incorrect.

BTW, errors are handled for JobExecutionListener#afterJob but not for JobExecutionListener#beforeJob in AbstractJob. Errors in the beforeJob methods should also be logged for consistency.

Affects: 4.0.1, 4.1.0

Referenced from: commits 30365ed, 2eb77c2, bf06ca5

Backported to: 4.2.0.M1, 4.1.2, 4.0.3

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 29, 2019

saikatbhadra commented

Pull request submitted: #680

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.