While debugging another issue, we noticed that some (most?) async methods at least in WsRemoteEndpointImplBase do not call the handler when erring but rather throw an exception. Here are examples: https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L204 https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L207 https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L1224 https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L799 These are coming from the "sendStringByCompletion" method. There's more async methods in this class and at least some of them have the same issues. I think this is a bug. The SendHandler's onResult method should be called instead.
The Java WebSocket spec requires IAE to be thrown when those methods are called with null data.
Thank you for the response. But did you see all the links I pasted? The third and fourth one are throwing not for null-arguments but for other error cases. Are they according to the spec too?
IllegalStateException on attempting to send messages concurrently is as per the spec. IllegalArgumentException on encoding to UTF-8 shouldn't happen. It is possible but a client would need to go out of its way to trigger it. This case is not explicitly covered in the spec so implementations are free to make their own choice. Tomcat opted to treat this illegal input the same way the more common illegal input of null is handled.