{"record":{"id":"11e84acd5e1f9da0","repo":"stanfordnlp/CoreNLP","slug":"invalid-buffer-size-buffersize-must-be-larger","errorCode":null,"errorMessage":"Invalid buffer size ${bufferSize}: must be larger than 0","messagePattern":"Invalid buffer size (.+?): must be larger than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ByteStreamGobbler.java","lineNumber":32,"sourceCode":"  int bufferSize = 4096;\n\n  public ByteStreamGobbler(InputStream is, OutputStream out) {\n    this.inStream = new BufferedInputStream(is);\n    this.outStream = new BufferedOutputStream(out);\n  }\n\n  public ByteStreamGobbler(String name, InputStream is, OutputStream out) {\n    super(name);\n    this.inStream = new BufferedInputStream(is);\n    this.outStream = new BufferedOutputStream(out);\n  }\n\n  public ByteStreamGobbler(String name, InputStream is, OutputStream out, int bufferSize) {\n    super(name);\n    this.inStream = new BufferedInputStream(is);\n    this.outStream = new BufferedOutputStream(out);\n    if (bufferSize <= 0) {\n      throw new IllegalArgumentException(\"Invalid buffer size \" + bufferSize + \": must be larger than 0\");\n    }\n    this.bufferSize = bufferSize;\n  }\n\n  public InputStream getInputStream()\n  {\n    return inStream;\n  }\n\n  public OutputStream getOutputStream()\n  {\n    return outStream;\n  }\n\n  public void run() {\n    try {\n      byte[] b = new byte[bufferSize];\n      int bytesRead;","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ByteStreamGobbler.java#L14-L50","documentation":"The ByteStreamGobbler constructor validates its bufferSize argument and throws IllegalArgumentException when it is zero or negative, because it is used to size buffered stream reading. The check happens after the streams are wrapped but before the buffer is used.","triggerScenarios":"Invoking new ByteStreamGobbler(name, is, out, bufferSize) with bufferSize <= 0, e.g. a default-uninitialized int field, a misparsed config value, or a size computed as 0.","commonSituations":"Configuration files with buffer size 0 or missing values defaulting to 0; calculations like (maxSize / numThreads) truncating to 0.","solutions":["Pass a positive buffer size, e.g. 4096 or 8192, at the call site.","Validate/clamp the value before constructing: Math.max(1, configuredSize) with a sane minimum like 1024.","Fix the config/source that produced 0 or a negative number (missing key, bad parse).","Add a defaults constant so callers never pass raw external values directly."],"exampleFix":"// before\nnew ByteStreamGobbler(\"proc\", is, out, cfg.getBufferSize()); // 0\n// after\nint size = Math.max(1024, cfg.getBufferSize());\nnew ByteStreamGobbler(\"proc\", is, out, size);","handlingStrategy":"validation","validationCode":"if (bufferSize <= 0) throw new IllegalArgumentException(\"bufferSize must be > 0, got \" + bufferSize);","typeGuard":"boolean isValidBufferSize(int n) { return n > 0; }","tryCatchPattern":"try { new ByteStreamGobbler(name, is, out, size); } catch (IllegalArgumentException e) { log.error(e.getMessage()); size = 8192; /* retry with default */ }","preventionTips":["Validate buffer-size config at load time","Clamp computed sizes with Math.max(minSize, value)","Avoid raw int fields for sizes without defaults","Never pass unparsed user input straight into constructors"],"tags":["java","io","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}