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

getSSLSession() throws IllegalArgumentException when the underlying channel is not an ISSLChannel — i.e. the connection was established over plain ws:// rather than wss://, so no SSLSession exists. The guard mirrors hasSSLSupport() returning false.

Solutions

  1. Check websocket.hasSSLSupport() before calling getSSLSession().
  2. Ensure the URI uses wss:// if SSL session data is required.
  3. Handle the non-SSL case with a fallback (skip certificate/cipher logging).

Example fix

// before
SSLSession s = conn.getSSLSession();
// after
if (conn.hasSSLSupport()) {
  SSLSession s = conn.getSSLSession();
}
Defensive patterns

Strategy: type-guard

Validate before calling

boolean sslOk = conn.hasSSLSupport();

Type guard

if (conn.hasSSLSupport()) { SSLSession s = conn.getSSLSession(); }

Try / catch

try { session = conn.getSSLSession(); } catch (IllegalArgumentException e) { session = null; /* ws:// connection */ }

Prevention

When it happens

Trigger: Calling websocket.getSSLSession() on a connection created with a ws:// URI, or before the channel is bound (channel is null / not SSL).

Common situations: Code written for TLS connections reused against non-TLS endpoints; SSL session inspection (cipher, peer certs) in onOpen for connections whose scheme is configurable; calling during handshake before the SSL channel is attached.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09). Data as JSON: /api/errors/b3ab2ae19006fd54. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/org/java_websocket/WebSocketImpl.java:876

  public WebSocketListener getWebSocketListener() {
    return wsl;
  }

  @Override
  @SuppressWarnings("unchecked")
  public <T> T getAttachment() {
    return (T) attachment;
  }

  @Override
  public boolean hasSSLSupport() {
    return channel instanceof ISSLChannel;
  }

  @Override
  public SSLSession getSSLSession() {
    if (!hasSSLSupport()) {
      throw new IllegalArgumentException(
          "This websocket uses ws instead of wss. No SSLSession available.");
    }
    return ((ISSLChannel) channel).getSSLEngine().getSession();
  }

  @Override
  public IProtocol getProtocol() {
    if (draft == null) {
      return null;
    }
    if (!(draft instanceof Draft_6455)) {
      throw new IllegalArgumentException("This draft does not support Sec-WebSocket-Protocol");
    }
    return ((Draft_6455) draft).getProtocol();
  }

  @Override
  public <T> void setAttachment(T attachment) {

View on GitHub (pinned to afeacbf8c0)