TooTallNate/Java-WebSocket · error · IllegalArgumentException
This draft does not support Sec-WebSocket-Protocol
Error message
This draft does not support Sec-WebSocket-Protocol
What it means
Thrown by WebSocketImpl.getProtocol() when the connection's negotiated draft is not Draft_6455. Protocol (subprotocol) negotiation via the Sec-WebSocket-Protocol header only exists in the RFC 6455 draft; older drafts (Draft_75/76/Hybi) carry no protocols, so querying getProtocol() on such a connection is a programming error rather than returning null. Fires only for non-6455 drafts with a non-null draft.
Solutions
- Check the negotiated draft before calling getProtocol(), e.g. `if (conn.getDraft() instanceof Draft_6455)`.
- Always use Draft_6455 (the default) on client and server so subprotocols are available.
- If no protocols may exist, treat a null return from getProtocol() (draft == null case) as 'unknown' instead of forcing a query on an unsupported draft.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at src/main/java/org/java_websocket/WebSocketImpl.java:888 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/68aeeaf3632e83d4.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/org/java_websocket/WebSocketImpl.java:888
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) {
this.attachment = attachment;
}
public ByteChannel getChannel() {
return channel;
}
public void setChannel(ByteChannel channel) {
this.channel = channel;
}
public WebSocketWorker getWorkerThread() {View on GitHub (pinned to afeacbf8c0)