TooTallNate/Java-WebSocket · error · IllegalArgumentException
This websocket uses ws instead of wss. No SSLSession…
Error message
This websocket uses ws instead of wss. No SSLSession available.
What it means
This is a pre-condition guard in WebSocketClient.getSSLSession: the method can only return an SSLSession when the underlying socket is an SSLSocket (i.e. the connection used the wss:// scheme). For a plain ws:// connection there is no TLS layer and therefore no session to expose, so the library throws rather than returning null. The faulty input is calling getSSLSession() (often indirectly through code that assumes TLS) on a websocket that was opened with ws instead of wss.
Solutions
- Check hasSSLSupport() before calling getSSLSession() and skip or branch when it returns false
- Use a wss:// URI (with proper SSLContext/SSLSocketFactory configuration) if an SSLSession is actually required
- Refactor caller code to not require TLS metadata when the connection is plain ws
- Wrap the call in a try-catch for IllegalArgumentException if the ws/wss scheme is determined at runtime
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:1003 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09).
Data as JSON: /api/errors/824b08608323c625.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:1003
@Override
public InetSocketAddress getRemoteSocketAddress() {
return engine.getRemoteSocketAddress();
}
@Override
public String getResourceDescriptor() {
return uri.getPath();
}
@Override
public boolean hasSSLSupport() {
return socket instanceof SSLSocket;
}
@Override
public SSLSession getSSLSession() {
if (!hasSSLSupport()) {
throw new IllegalArgumentException(
"This websocket uses ws instead of wss. No SSLSession available.");
}
return ((SSLSocket)socket).getSession();
}
@Override
public IProtocol getProtocol() {
return engine.getProtocol();
}
/**
* Method to give some additional info for specific IOExceptions
*
* @param e the IOException causing a eot.
*/
private void handleIOException(IOException e) {
if (e instanceof SSLException) {
onError(e);View on GitHub (pinned to afeacbf8c0)