https://bz.apache.org/bugzilla/show_bug.cgi?id=65458
Bug ID: 65458 Summary: NPE when using a lambda in Session.addMessageHandler Product: Tomcat 8 Version: 8.5.50 Hardware: PC OS: Mac OS X 10.1 Status: NEW Severity: critical Priority: P2 Component: WebSocket Assignee: dev@tomcat.apache.org Reporter: elecha...@apache.org Target Milestone: ---- This is close to 57788. When we write that: session.addMessageHandler( ( MessageHandler.Whole<String> ) msg -> { ...}) ; we get a NPE: java.lang.NullPointerException at org.apache.tomcat.websocket.Util.getGenericType(Util.java:216) at org.apache.tomcat.websocket.Util.getMessageType(Util.java:170) at org.apache.tomcat.websocket.WsSession.addMessageHandler(WsSession.java:206) OTOH, doing that : session.addMessageHandler( new MessageHandler.Whole<String>() { ... }); works just fine. I think it's because MessageHandler.Whole is an Interface, and not a class, when in the second piece of code we have a class that get created. Of course, there might be some Java side effect I don't know about, but at this point, this is what I infer from the Tomcat code (org.apache.tomcat.websocket.Util): 185 private static <T> TypeResult getGenericType(Class<T> type, Class<? extends T> clazz) { // Look to see if this class implements the interface of interest 190 // Get all the interfaces Type[] interfaces = clazz.getGenericInterfaces(); for (Type iface : interfaces) { ... (ignored because it's not a Parameterized type) } 206 // Interface not found on this class. Look at the superclass. @SuppressWarnings("unchecked") Class<? extends T> superClazz = (Class<? extends T>) clazz.getSuperclass(); if (superClazz == null) { // Finished looking up the class hierarchy without finding anything return null; } Here, Whole extends MessageHandler so we keep going : 215 TypeResult superClassTypeResult = getGenericType(type, superClazz); and the recursive call do the same thing with the MessageHandler interface, which has no parent, thus returns null : 210 if (superClazz == null) { // Finished looking up the class hierarchy without finding anything return null; } and back to the caller (the same method) on line : 216 int dimension = superClassTypeResult.getDimension(); and SNAP because superClassTypeResult is null. Note: the pb should also occurs on 8.5.69 (same code) and I guess in TC 9 and TC 10. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org