-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
has: backportsLegacy label from JIRA. Superseded by "for: backport-to-x.x.x"Legacy label from JIRA. Superseded by "for: backport-to-x.x.x"type: bug
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
has: backportsLegacy label from JIRA. Superseded by "for: backport-to-x.x.x"Legacy label from JIRA. Superseded by "for: backport-to-x.x.x"type: bug