TooTallNate/Java-WebSocket · error · IllegalArgumentException

http resource descriptor must not be null

Error message

http resource descriptor must not be null

What it means

HandshakeImpl1Client.setResourceDescriptor() throws IllegalArgumentException when handed a null resource descriptor. The resource descriptor is the HTTP request path (e.g. "/path?query") of the handshake and must always be a non-null string; the field defaults to "*".

Solutions

  1. Never pass null; default to "/" when the path is missing
  2. Before calling, check the request's path/URI for null and substitute a sensible default
  3. If triggered inside translateHandshakeHttpServer, validate the raw HTTP request line before translating the handshake

Example fix

// before
handshake.setResourceDescriptor(request.getPath()); // may be null
// after
String path = request.getPath();
handshake.setResourceDescriptor(path != null ? path : "/");
Defensive patterns

Strategy: type-guard

Validate before calling

if (path == null || path.isEmpty()) { path = "/"; }

Type guard

String safeDescriptor(String path) {
  return (path == null || path.isEmpty()) ? "/" : path;
}

Try / catch

try {
  handshake.setResourceDescriptor(path);
} catch (IllegalArgumentException e) {
  handshake.setResourceDescriptor("/");
}

Prevention

When it happens

Trigger: Calling setResourceDescriptor(null) directly, or via translateHandshakeHttpServer when the incoming HTTP request has no usable path/URI (e.g. a malformed request line).

Common situations: Custom handshake translation code, HTTP clients issuing requests without a path, or proxies stripping the request URI.

Related errors


AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09). Data as JSON: /api/errors/149c86d1bad8a0c5. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/org/java_websocket/handshake/HandshakeImpl1Client.java:41

 *  OTHER DEALINGS IN THE SOFTWARE.
 */

package org.java_websocket.handshake;

/**
 * Implementation for a client handshake
 */
public class HandshakeImpl1Client extends HandshakedataImpl1 implements ClientHandshakeBuilder {

  /**
   * Attribute for the resource descriptor
   */
  private String resourceDescriptor = "*";

  @Override
  public void setResourceDescriptor(String resourceDescriptor) {
    if (resourceDescriptor == null) {
      throw new IllegalArgumentException("http resource descriptor must not be null");
    }
    this.resourceDescriptor = resourceDescriptor;
  }

  @Override
  public String getResourceDescriptor() {
    return resourceDescriptor;
  }
}

View on GitHub (pinned to afeacbf8c0)