Affects: v4.3.0.RELEASE
In the v4.3.0.RELEASE release a change was made to the ExceptionHandler
mechanism so that it not only matches handlers based on the observed exception but also the on the first level cause of that exception.
This is problematic in scenarios like the following:
class Controller {
void endpoint1() {
throw new ExceptionA();
}
void endpoint2() {
try {
...
} catch (ExceptionA e) {
throw new ExceptionB(e);
}
}
if ExceptionA is thrown is want the ExceptionA
handler to be used, but if ExceptionB
is thrown, then i want the handler for ExceptionB to be used.
I believe that should be the case regardless of the order of the handlers, because when an exception is caught and wrapped it is the outer exception that is intended to be surfaced and also what has more relevant high level information of what failed, details belong in the logs. (eg: ExceptionA
could be IllegalArgumentException
, while ExceptionB
could be InvalidUsernameException
).
In addition to that, having added that feature changed the behavior of the handlers and potentially exposed details that were not intended to be public.
I suggest that such this is made optional and disabled by default (or, preferably, removed), if kept, looking at the first cause seem arbitrary, why not the second cause? why not the root cause? why not any exception in cause chain?
Comment From: rstoyanchev
This change #18863 was made quite a bit earlier, making it challenging to change or revert. It was later followed up with another change #23380 to match against every cause starting in 5.3.
I do think there are valid reasons to match to the root cause, but I appreciate that there are other situations where that doesn't work out as well. We could look to allow enough flexibility to be able to change the behavior in this regard.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.