{"record":{"id":"ee50a687abd61e4a","repo":"TooTallNate/Java-WebSocket","slug":"parameters-must-not-be-null","errorCode":null,"errorMessage":"parameters must not be null","messagePattern":"parameters must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/WebSocketImpl.java","lineNumber":204,"sourceCode":"    // draft.copyInstance will be called when the draft is first needed\n    if (drafts == null || drafts.isEmpty()) {\n      knownDrafts = new ArrayList<>();\n      knownDrafts.add(new Draft_6455());\n    } else {\n      knownDrafts = drafts;\n    }\n  }\n\n  /**\n   * creates a websocket with client role\n   *\n   * @param listener The listener for this instance\n   * @param draft    The draft which should be used\n   */\n  public WebSocketImpl(WebSocketListener listener, Draft draft) {\n    // socket can be null because we want do be able to create the object without already having a bound channel\n    if (listener == null || (draft == null && role == Role.SERVER)) {\n      throw new IllegalArgumentException(\"parameters must not be null\");\n    }\n    this.outQueue = new LinkedBlockingQueue<>();\n    inQueue = new LinkedBlockingQueue<>();\n    this.wsl = listener;\n    this.role = Role.CLIENT;\n    if (draft != null) {\n      this.draft = draft.copyInstance();\n    }\n  }\n\n  /**\n   * Method to decode the provided ByteBuffer\n   *\n   * @param socketBuffer the ByteBuffer to decode\n   */\n  public void decode(ByteBuffer socketBuffer) {\n    assert (socketBuffer.hasRemaining());\n    if (log.isTraceEnabled()) {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/WebSocketImpl.java#L186-L222","documentation":"The WebSocketImpl constructor throws IllegalArgumentException when the WebSocketListener is null, or when both the Draft is null and the role is SERVER — a server-side socket cannot negotiate without a draft. It is a fail-fast guard because the object is unusable without a listener.","triggerScenarios":"Passing null as the WebSocketListener to new WebSocketImpl(listener, draft), or constructing a server-role WebSocketImpl with draft == null.","commonSituations":"Custom WebSocketServer implementations subclassing WebSocketImpl and passing a wrong/uninitialized listener reference (e.g. 'this' before initialization); reflection-based instantiation with missing arguments.","solutions":["Always pass a valid WebSocketListener (usually the WebSocketServer/WebSocketClient instance).","Pass a concrete Draft (e.g. new Draft_6455()) when constructing server-role instances.","If you control the code, check listener/draft for null before invoking the constructor."],"exampleFix":"// before\nWebSocketImpl ws = new WebSocketImpl(null, null);\n// after\nWebSocketImpl ws = new WebSocketImpl(this, new Draft_6455());","handlingStrategy":"validation","validationCode":"if (listener == null || (role == Role.SERVER && draft == null)) {\n  throw new IllegalArgumentException(\"listener required; draft required for server role\");\n}","typeGuard":null,"tryCatchPattern":"try { new WebSocketImpl(listener, draft); } catch (IllegalArgumentException e) { log.error(\"bad websocket args\", e); }","preventionTips":["Never pass a null listener","Always supply a Draft for server-role sockets","Validate constructor inputs in subclasses before super(...)"],"tags":["null-check","constructor","illegal-argument"],"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"}