Uploaded image for project: 'Spring Batch'
  1. Spring Batch
  2. BATCH-2213

Original exception wrapped in IllegalArgumentException/InvocationTargetException in annotated step listeners

    Details

      Description

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

        Attachments

          Activity

            People

            • Assignee:
              mbenhassine Mahmoud Ben Hassine
              Reporter:
              m.adebahr Mirko Adebahr
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: