[BATCH-2213] Original exception wrapped in IllegalArgumentException/InvocationTargetException in annotated step listeners Created: 16/Apr/14  Updated: 17/Dec/19  Resolved: 02/May/18

Status: Resolved
Project: Spring Batch
Component/s: None
Affects Version/s: 2.2.2
Fix Version/s: 4.1.0, 4.1.0.M1

Type: Bug Priority: Minor
Reporter: Mirko Adebahr Assignee: Mahmoud Ben Hassine
Resolution: Complete Votes: 0
Labels: pull-request-submitted
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Pull Request URL: https://github.com/spring-projects/spring-batch/pull/584


If an exception is thrown from a method with a listener annotation like @AfterProcess, the original exception passed to onProcessError() or onSkipInProcess() is wrapped as follows:

StepListenerFailedException -> IllegalArgumentException -> InvocationTargetException -> #getTargetException()

If an implementation of ItemProcessListener is registered (no annotations), the original exception is the direct cause of the StepListenerFailedException as expected.

Expected behaviour is that in both cases the original exception can be obtained by StepListenerFailedException#getCause().


public void afterProcess(final I i, final O o) {
	throw new RuntimeException("Cause");


public void onProcessError(final I i, final Exception e) {
	if (e instanceof StepListenerFailedException) {
		Throwable cause = e.getCause();
		if ((cause instanceof IllegalArgumentException)
				&& (cause.getCause() instanceof InvocationTargetException)) {
			cause =
					((InvocationTargetException) cause.getCause())
			// now cause is the original runtime exception thrown in afterProcess()

Comment by Seo Kyung-Seok [ 01/Jul/14 ]

This problem is occurred in SimpleMethodInvoker.invokeMethod(Object...). If a exception was occurred after the method.invoke(target, invokeArgs) was executed In SimpleMethodInvoker.invokeMethod(Object...), the exception(IllegalAccessException, IllegalArgumentException and InvocationTargetException) is wrapped a IllegalArgumentException. So, it is more efficient that using ReflectionUtils.handleReflectionException(e) in the method. In this case, the (@OnProcessError)onProcessError() method is not neccessary.

And I submitted pull request.

Comment by Seo Kyung-Seok [ 01/Jul/14 ]

This issue assignee isn't specified yet.

Comment by Seo Kyung-Seok [ 09/Jul/14 ]

I made the pull request in 3.0.x branch.



Comment by Michael Minella [ 02/May/18 ]

Merged asĀ 61bec2805dda06b25f1dd5c3030066754cdf7b94.

Comment by Spring Issuemaster [ 17/Dec/19 ]

The Spring Batch Framework has moved from Jira to GitHub Issues. This issue was migrated to spring-projects/spring-batch#1387.

Generated at Fri Aug 14 14:11:54 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.