Hi
I just got the following NPE in tomcat:
java.lang.NullPointerException
at org.apache.tomcat.websocket.Util.getGenericType(Util.java:217)
at org.apache.tomcat.websocket.Util.getMessageType(Util.java:171)
at
org.apache.tomcat.websocket.WsSession.addMessageHandler(WsSession.java:198)
at ...
at
org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.init(WsHttpUpgradeHandler.java:138)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:701)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
That happened because eclipse "cleaned up" my code:
session.addMessageHandler( new
MessageHandler.Whole<String>() {
@Override
public void onMessage( String text )
{
processor.received( text );
}
} );
session.addMessageHandler( new
MessageHandler.Whole<ByteBuffer>() {
@Override
public void onMessage( ByteBuffer data )
{
processor.received( data );
}
} );
Resulting in:
session.addMessageHandler( (Whole<String>) text ->
processor.received( text ) );
session.addMessageHandler( (Whole<ByteBuffer>) data ->
processor.received( data ) );
So I understand that tomcat tries to get the type of the message handler using
reflection.
While I believe this is a bad API, it's not tomcats fault. However it should
not throw a NPE...
But I think there is no other way for the to register message handlers, right?
So do I need to stick to the anonymous classes or is there a way to make it
work with lambdas?
Regards,
Steffen
smime.p7s
Description: S/MIME cryptographic signature
