{"record":{"id":"32d30be877af5640","repo":"TooTallNate/Java-WebSocket","slug":"buffer-size-0","errorCode":null,"errorMessage":"buffer size < 0","messagePattern":"buffer size < 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/AbstractWebSocket.java","lineNumber":371,"sourceCode":"   * Returns the TCP receive buffer size that will be used for sockets (or zero, if not explicitly set).\n   * @see java.net.Socket#setReceiveBufferSize(int)\n   *\n   * @since 1.5.7\n   */\n  public int getReceiveBufferSize() {\n    return receiveBufferSize;\n  }\n\n  /**\n   * Sets the TCP receive buffer size that will be used for sockets.\n   * If this is not explicitly set (or set to zero), the system default is used.\n   * @see java.net.Socket#setReceiveBufferSize(int)\n   *\n   * @since 1.5.7\n   */\n  public void setReceiveBufferSize(int receiveBufferSize) {\n    if (receiveBufferSize < 0) {\n      throw new IllegalArgumentException(\"buffer size < 0\");\n    }\n    this.receiveBufferSize = receiveBufferSize;\n  }\n\n}\n","sourceCodeStart":353,"sourceCodeEnd":377,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/AbstractWebSocket.java#L353-L377","documentation":"setReceiveBufferSize() validates its argument before storing it on AbstractWebSocket. A negative value is never a legal socket receive-buffer size, so the library throws IllegalArgumentException immediately rather than letting the value propagate to Socket.setReceiveBufferSize().","triggerScenarios":"Calling WebSocketAdapter/AbstractWebSocket.setReceiveBufferSize() with a negative int, typically from unparsed or miscomputed configuration (e.g. Integer.parseInt of '-1', a sentinel value, or an underflow in a size calculation).","commonSituations":"Config files or env vars where the buffer size is negative or a placeholder like -1 meaning 'unset' was passed through instead of skipping the call.","solutions":["Pass a positive receiveBufferSize (e.g. >= 8192 bytes) or 0 to leave the OS default","Fix the config parsing so sentinel values like -1 are treated as 'use default' and the setter is not called","Validate/clamp the value before calling: if (size >= 0) ws.setReceiveBufferSize(size);"],"exampleFix":"// before\nint size = Integer.parseInt(cfg.get(\"recvBuf\")); // \"-1\"\nwebsocket.setReceiveBufferSize(size); // throws\n// after\nint size = Integer.parseInt(cfg.get(\"recvBuf\"));\nif (size >= 0) {\n  websocket.setReceiveBufferSize(size);\n}","handlingStrategy":"validation","validationCode":"if (size < 0) throw new IllegalArgumentException(\"receiveBufferSize must be >= 0, got \" + size);\nwebsocket.setReceiveBufferSize(size);","typeGuard":null,"tryCatchPattern":"try { ws.setReceiveBufferSize(size); } catch (IllegalArgumentException e) { log.warn(\"Invalid buffer size, using default\", e); }","preventionTips":["Never pass sentinel values like -1 straight from config into the setter","Clamp/validate all numeric socket options at config-load time"],"tags":["websocket","illegal-argument","configuration"],"backgroundTag":"invalid-argument-value","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"}