Bug 57788 - NPE on session.addMessageHandler
Summary: NPE on session.addMessageHandler
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: WebSocket (show other bugs)
Version: 8.0.21
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-02 21:51 UTC by Marco
Modified: 2015-04-13 12:24 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco 2015-04-02 21:51:07 UTC
The NPE is throwed when then MessageHandler has no Generic Class.

java.lang.NullPointerException
	at org.apache.tomcat.websocket.Util.getGenericType(Util.java:192)
	at org.apache.tomcat.websocket.Util.getGenericType(Util.java:212)
	at org.apache.tomcat.websocket.Util.getGenericType(Util.java:212)
	at org.apache.tomcat.websocket.Util.getGenericType(Util.java:212)
	at org.apache.tomcat.websocket.Util.getMessageType(Util.java:171)
	at org.apache.tomcat.websocket.WsSession.addMessageHandler(WsSession.java:198)

Please check on the Util class line 210. The call clazz.getSuperclass() returns null if clazz is a Object class (see JDK Javadoc).
Comment 1 Konstantin Kolinko 2015-04-04 00:45:54 UTC
What are you trying to do here and what do you expect? Is it a real use case? 

(Source code =?)

My expectations are that such call is expected to fail.

For reference, WsSession.addMessageHandler(WsSession.java:198) method called here is

[[[
    @Override
    public void addMessageHandler(MessageHandler listener) {
]]]

declared in javax.websocket.Session.

Use of that method is discouraged in favor of WebSocket 1.1 methods

Session.addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler)
Session.addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler)
Comment 2 Remy Maucherat 2015-04-13 08:40:46 UTC
r1672628, will be included in 8.0.22. Of course, it will only display a different error. Source for better test ?
Comment 3 Remy Maucherat 2015-04-13 12:24:05 UTC
r1673169 for 7.0.62.