-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
@ExceptionHandler methods not invokable if matched on exception's cause level > 1 #26317
Comments
Just added a demo project to illustrate the problem: |
the cause is: i think it should be a nested finding |
@dongbaibai, |
@rod2j as far as I can tell, such a exception handler for a more deeply nested cause would not have matched at all previously. Do you really mean regression or a bug? |
Hi @rstoyanchev ,
So after migrating to 5.3.2 this |
Okay so an existing exception handler may get matched where it didn't before which prevents further handling that might have happened before. Thanks. |
This PR #26366 is one of the 2 solutions I thought about to fix this issue and the one requiring the least code / tests change:
A second solution, more elegant IMO, but requiring more code change, and even more tests change is the following:
Last question: Reference Documentation and Javadoc for ExceptionHandler will need some updates about this, which is not included yet. |
There seems to be an easier - and pretty local - solution: simply building a list of all causes for the |
Hi @jhoeller, |
Good point, I'll revise those documentation bits before the 5.3.3 release still. Thanks for the reminder! |
Affects: 5.3.2
It looks like PR #23380 introduced a major regression in the way exceptions are handled by @ControllerAdvice components.
Before that PR was merged, Spring resolved @ExceptionHandler methods only on the main exception or its 1st level cause.
ExceptionHandlerExceptionResolver
was aligned with that, and after resolution it would invoke the resolved method by using the exception and its cause as 'candidate' arguments for the target method:But PR #23380 didn't come with any change in the way arguments of the target method are resolved... and that's the problem.
Whenever the
@ExceptionHandler
method is resolved due to a match on a cause above the 1st level, and if a throwable of this type is used as an argument of the method, ExceptionHandlerExceptionResolver has no way to resolve this argument as it still only tries the main exception and its 1st cause.So if we do this in a controller...
... and have this kind of
@ControllerAdvice
:... then the
handleIllegalArgumentException
is resolved but actually not invokable when exception thrown is like in the code above, and we get this in the log:So if the changes made by PR #23380 are to be kept, i.e. @ExceptionHandler methods have to be able to handle any cause in the causality chain of an exception, a change of design is necessary in arguments resolution.
Regards
The text was updated successfully, but these errors were encountered: