TooTallNate/Java-WebSocket · error · IllegalArgumentException
null as draft is permitted for `WebSocketServer` only!
Error message
null as draft is permitted for `WebSocketServer` only!
What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:216 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/05b8e210f97f8e96.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/org/java_websocket/client/WebSocketClient.java:216
this(serverUri, protocolDraft, httpHeaders, 0);
}
/**
* Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The
* channel does not attampt to connect automatically. The connection will be established once you
* call <var>connect</var>.
*
* @param serverUri the server URI to connect to
* @param protocolDraft The draft which should be used for this connection
* @param httpHeaders Additional HTTP-Headers
* @param connectTimeout The Timeout for the connection
*/
public WebSocketClient(URI serverUri, Draft protocolDraft, Map<String, String> httpHeaders,
int connectTimeout) {
if (serverUri == null) {
throw new IllegalArgumentException();
} else if (protocolDraft == null) {
throw new IllegalArgumentException("null as draft is permitted for `WebSocketServer` only!");
}
this.uri = serverUri;
this.draft = protocolDraft;
this.dnsResolver = new DnsResolver() {
@Override
public InetAddress resolve(URI uri) throws UnknownHostException {
return InetAddress.getByName(uri.getHost());
}
};
if (httpHeaders != null) {
headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.putAll(httpHeaders);
}
this.connectTimeout = connectTimeout;
setTcpNoDelay(false);
setReuseAddr(false);
this.engine = new WebSocketImpl(this, protocolDraft);
}View on GitHub (pinned to afeacbf8c0)