{"record":{"id":"824b08608323c625","repo":"TooTallNate/Java-WebSocket","slug":"this-websocket-uses-ws-instead-of-wss-no-sslsessi-824b08","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/client/WebSocketClient.java","lineNumber":1003,"sourceCode":"  @Override\n  public InetSocketAddress getRemoteSocketAddress() {\n    return engine.getRemoteSocketAddress();\n  }\n\n  @Override\n  public String getResourceDescriptor() {\n    return uri.getPath();\n  }\n\n  @Override\n  public boolean hasSSLSupport() {\n    return socket instanceof SSLSocket;\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 ((SSLSocket)socket).getSession();\n  }\n\n  @Override\n  public IProtocol getProtocol() {\n    return engine.getProtocol();\n  }\n\n  /**\n   * Method to give some additional info for specific IOExceptions\n   *\n   * @param e the IOException causing a eot.\n   */\n  private void handleIOException(IOException e) {\n    if (e instanceof SSLException) {\n      onError(e);","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/client/WebSocketClient.java#L985-L1021","documentation":"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.","triggerScenarios":"Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:1003 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}