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

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

Comments

@spring-issuemaster
Copy link
Collaborator

@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") {

	@Override
	public Step getStep(String stepName) {
		return null;
	}

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

	@Override
	protected void doExecute(JobExecution jobExecution) {
		System.out.println("executing job");
		jobExecution.setStatus(BatchStatus.COMPLETED);
		jobExecution.setExitStatus(ExitStatus.COMPLETED);
	}


};
job.setJobRepository(jobRepository);
job.registerJobExecutionListener(new JobExecutionListener() {
	@Override
	public void beforeJob(JobExecution jobExecution) {
		System.out.println("before job");
	}

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

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

// 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

@spring-issuemaster
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
Projects
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.