{"record":{"id":"b3ab2ae19006fd54","repo":"TooTallNate/Java-WebSocket","slug":"this-websocket-uses-ws-instead-of-wss-no-sslsessi","errorCode":null,"errorMessage":"This websocket uses ws instead of wss. No SSLSession available.","messagePattern":"This websocket uses ws instead of wss\\. No SSLSession available\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/WebSocketImpl.java","lineNumber":876,"sourceCode":"  public WebSocketListener getWebSocketListener() {\n    return wsl;\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  public <T> T getAttachment() {\n    return (T) attachment;\n  }\n\n  @Override\n  public boolean hasSSLSupport() {\n    return channel instanceof ISSLChannel;\n  }\n\n  @Override\n  public SSLSession getSSLSession() {\n    if (!hasSSLSupport()) {\n      throw new IllegalArgumentException(\n          \"This websocket uses ws instead of wss. No SSLSession available.\");\n    }\n    return ((ISSLChannel) channel).getSSLEngine().getSession();\n  }\n\n  @Override\n  public IProtocol getProtocol() {\n    if (draft == null) {\n      return null;\n    }\n    if (!(draft instanceof Draft_6455)) {\n      throw new IllegalArgumentException(\"This draft does not support Sec-WebSocket-Protocol\");\n    }\n    return ((Draft_6455) draft).getProtocol();\n  }\n\n  @Override\n  public <T> void setAttachment(T attachment) {","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/WebSocketImpl.java#L858-L894","documentation":"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.","triggerScenarios":"Calling websocket.getSSLSession() on a connection created with a ws:// URI, or before the channel is bound (channel is null / not SSL).","commonSituations":"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.","solutions":["Check websocket.hasSSLSupport() before calling getSSLSession().","Ensure the URI uses wss:// if SSL session data is required.","Handle the non-SSL case with a fallback (skip certificate/cipher logging)."],"exampleFix":"// before\nSSLSession s = conn.getSSLSession();\n// after\nif (conn.hasSSLSupport()) {\n  SSLSession s = conn.getSSLSession();\n}","handlingStrategy":"type-guard","validationCode":"boolean sslOk = conn.hasSSLSupport();","typeGuard":"if (conn.hasSSLSupport()) { SSLSession s = conn.getSSLSession(); }","tryCatchPattern":"try { session = conn.getSSLSession(); } catch (IllegalArgumentException e) { session = null; /* ws:// connection */ }","preventionTips":["Call hasSSLSupport() before getSSLSession()","Use wss:// URIs when TLS metadata is needed","Handle both ws and wss in shared connection-inspection code"],"tags":["ssl","tls","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d","analyzedAt":"2026-09-09T14:39:47.546Z","contentChangedAt":"2026-09-09T14:39:47.546Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}