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

Original exception wrapped in IllegalArgumentException/InvocationTargetException in annotated step listeners [BATCH-2213] #1387

Closed
spring-issuemaster opened this issue Apr 16, 2014 · 4 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Apr 16, 2014

Mirko Adebahr opened BATCH-2213 and commented

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().

Example:

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

...

@OnProcessError
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())
							.getTargetException();
			// now cause is the original runtime exception thrown in afterProcess()
		}
	}
}

Affects: 2.2.2

Referenced from: pull request #584, and commits 61bec28

Backported to: 4.1.0.M1

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 1, 2014

Seo Kyung-Seok commented

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.
#332

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 1, 2014

Seo Kyung-Seok commented

This issue assignee isn't specified yet.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 9, 2014

Seo Kyung-Seok commented

I made the pull request in 3.0.x branch.

#338

Thanks.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 2, 2018

Michael Minella commented

Merged as 61bec2805dda06b25f1dd5c3030066754cdf7b94.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.