{"record":{"id":"0a91761265fd196c","repo":"TooTallNate/Java-WebSocket","slug":"address-and-connectionscontainer-must-not-be-null","errorCode":null,"errorMessage":"address and connectionscontainer must not be null and you need at least 1 decoder","messagePattern":"address and connectionscontainer must not be null and you need at least 1 decoder","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/server/WebSocketServer.java","lineNumber":234,"sourceCode":"   * @param drafts               The versions of the WebSocket protocol that this server instance\n   *                             should comply to. Clients that use an other protocol version will\n   *                             be rejected.\n   * @param connectionscontainer Allows to specify a collection that will be used to store the\n   *                             websockets in. <br> If you plan to often iterate through the\n   *                             currently connected websockets you may want to use a collection\n   *                             that does not require synchronization like a {@link\n   *                             CopyOnWriteArraySet}. In that case make sure that you overload\n   *                             {@link #removeConnection(WebSocket)} and {@link\n   *                             #addConnection(WebSocket)}.<br> By default a {@link HashSet} will\n   *                             be used.\n   * @see #removeConnection(WebSocket) for more control over syncronized operation\n   * @see <a href=\"https://github.com/TooTallNate/Java-WebSocket/wiki/Drafts\" > more about\n   * drafts</a>\n   */\n  public WebSocketServer(InetSocketAddress address, int decodercount, List<Draft> drafts,\n      Collection<WebSocket> connectionscontainer) {\n    if (address == null || decodercount < 1 || connectionscontainer == null) {\n      throw new IllegalArgumentException(\n          \"address and connectionscontainer must not be null and you need at least 1 decoder\");\n    }\n\n    if (drafts == null) {\n      this.drafts = Collections.emptyList();\n    } else {\n      this.drafts = drafts;\n    }\n\n    this.address = address;\n    this.connections = connectionscontainer;\n    setTcpNoDelay(false);\n    setReuseAddr(false);\n    iqueue = new LinkedList<>();\n\n    decoders = new ArrayList<>(decodercount);\n    buffers = new LinkedBlockingQueue<>();\n    for (int i = 0; i < decodercount; i++) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/server/WebSocketServer.java#L216-L252","documentation":"Constructor validation in WebSocketServer(InetSocketAddress, int, List<Draft>, Collection<WebSocket>): the bind address and the connections container must be non-null and the decoder count must be at least 1. The decoder workers are created eagerly in the constructor, so zero decoders would make the server unable to process incoming frames.","triggerScenarios":"Passing null as the InetSocketAddress, passing null for the connections container, or passing decodercount < 1 (e.g. 0 or a config-derived value of 0) to the 4-arg WebSocketServer constructor.","commonSituations":"Building the server from configuration where the listen address or port was never parsed (null slips through); tuning thread counts from properties and getting 0; refactoring that passes a null collection instead of a fresh empty collection.","solutions":["Pass a valid address: new InetSocketAddress(port) or InetAddress.getByName(host) with a port.","Pass a live, mutable collection for connectionscontainer, e.g. new ConcurrentHashMap().keySet() or new CopyOnWriteArraySet<>().","Use decodercount >= 1, typically a small positive number sized to expected load.","Prefer the simpler WebSocketServer(InetSocketAddress) constructor and configure threads/drafts via setters if you do not need the full 4-arg form."],"exampleFix":"// before\nWebSocketServer server = new WebSocketServer(null, 0, drafts, connections);\n// after\nWebSocketServer server = new WebSocketServer(\n    new InetSocketAddress(8887), 2, drafts, new CopyOnWriteArraySet<>());","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(address, \"address must not be null\");\nObjects.requireNonNull(connections, \"connectionscontainer must not be null\");\nif (decodercount < 1) throw new IllegalArgumentException(\"decodercount must be >= 1\");","typeGuard":null,"tryCatchPattern":"try {\n  server = new WebSocketServer(address, decodercount, drafts, connections);\n} catch (IllegalArgumentException e) {\n  log.error(\"Invalid WebSocketServer arguments: {}\", e.getMessage());\n  server = new WebSocketServer(address != null ? address : new InetSocketAddress(8080));\n}","preventionTips":["Load address/port from config with explicit defaults and fail fast if missing","Never pass a raw nullable Collection; always construct a fresh Set (e.g. CopyOnWriteArraySet)","Keep decoder counts >= 1; treat 0 from configuration as invalid and clamp to a default"],"tags":["websocket","constructor","validation"],"backgroundTag":"invalid-constructor-argument","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"}