{"record":{"id":"05b8e210f97f8e96","repo":"TooTallNate/Java-WebSocket","slug":"null-as-draft-is-permitted-for-websocketserver-o","errorCode":null,"errorMessage":"null as draft is permitted for `WebSocketServer` only!","messagePattern":"null as draft is permitted for `WebSocketServer` only!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/client/WebSocketClient.java","lineNumber":216,"sourceCode":"    this(serverUri, protocolDraft, httpHeaders, 0);\n  }\n\n  /**\n   * Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The\n   * channel does not attampt to connect automatically. The connection will be established once you\n   * call <var>connect</var>.\n   *\n   * @param serverUri      the server URI to connect to\n   * @param protocolDraft  The draft which should be used for this connection\n   * @param httpHeaders    Additional HTTP-Headers\n   * @param connectTimeout The Timeout for the connection\n   */\n  public WebSocketClient(URI serverUri, Draft protocolDraft, Map<String, String> httpHeaders,\n      int connectTimeout) {\n    if (serverUri == null) {\n      throw new IllegalArgumentException();\n    } else if (protocolDraft == null) {\n      throw new IllegalArgumentException(\"null as draft is permitted for `WebSocketServer` only!\");\n    }\n    this.uri = serverUri;\n    this.draft = protocolDraft;\n    this.dnsResolver = new DnsResolver() {\n      @Override\n      public InetAddress resolve(URI uri) throws UnknownHostException {\n        return InetAddress.getByName(uri.getHost());\n      }\n    };\n    if (httpHeaders != null) {\n      headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);\n      headers.putAll(httpHeaders);\n    }\n    this.connectTimeout = connectTimeout;\n    setTcpNoDelay(false);\n    setReuseAddr(false);\n    this.engine = new WebSocketImpl(this, protocolDraft);\n  }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/client/WebSocketClient.java#L198-L234","documentation":"Constructor validation in WebSocketClient(URI, Draft, Map, int): the client requires an explicit non-null Draft because it must send a concrete handshake during connect. A null draft is only meaningful server-side, where WebSocketServer picks the best draft per handshake, hence the sentinel message.","triggerScenarios":"Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:216 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a concrete draft, typically `new Draft_6455()`, to the WebSocketClient constructor.","If you want default behavior, use the single-argument constructor WebSocketClient(serverUri), which defaults to Draft_6455.","If draft selection should be dynamic, keep null drafts on the server side only."],"exampleFix":null,"handlingStrategy":"validation","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"}