Bug 56446 - Handling InvocationTargetException for PojoMessageHandlerWholeBase and PojoMessageHandlerPartialBase.onMessage()
Summary: Handling InvocationTargetException for PojoMessageHandlerWholeBase and PojoMe...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: WebSocket (show other bugs)
Version: 8.0.x-trunk
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-23 02:11 UTC by Eugene Chung (TmaxSoft)
Modified: 2014-09-13 05:29 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Chung (TmaxSoft) 2014-04-23 02:11:22 UTC
Both two methods handle InvocationTargetException from Endpoint @OnMessage method like this:

        try {
            result = method.invoke(pojo, parameters);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new IllegalArgumentException(e);
        }

I'd like to suggest to use

org.apache.tomcat.util.ExceptionUtils#unwrapInvocationTargetException() and RuntimeException

, which is like below:

        try {
            result = method.invoke(pojo, parameters);
        } catch (IllegalAccessException | InvocationTargetException e) {
            Throwable throwable = ExceptionUtils.unwrapInvocationTargetException(e);
            if (throwable instanceof RuntimeException) {
                throw (RuntimeException) throwable;
            } else {
                throw new RuntimeException(throwable);
            }
        }
Comment 1 Mark Thomas 2014-05-19 13:33:30 UTC
Thanks for the report. I have applied a variation of this to 8.0.x for 8.0.9 onwards.
Comment 2 Violeta Georgieva 2014-09-13 05:29:24 UTC
The fix was back-ported to 7.0.x for 7.0.56 onwards.