stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid buffer size : must be larger than 0

Error message

Invalid buffer size ${bufferSize}: must be larger than 0

What it means

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.

Solutions

  1. Pass a positive buffer size, e.g. 4096 or 8192, at the call site.
  2. Validate/clamp the value before constructing: Math.max(1, configuredSize) with a sane minimum like 1024.
  3. Fix the config/source that produced 0 or a negative number (missing key, bad parse).
  4. Add a defaults constant so callers never pass raw external values directly.

Example fix

// before
new ByteStreamGobbler("proc", is, out, cfg.getBufferSize()); // 0
// after
int size = Math.max(1024, cfg.getBufferSize());
new ByteStreamGobbler("proc", is, out, size);
Defensive patterns

Strategy: validation

Validate before calling

if (bufferSize <= 0) throw new IllegalArgumentException("bufferSize must be > 0, got " + bufferSize);

Type guard

boolean isValidBufferSize(int n) { return n > 0; }

Try / catch

try { new ByteStreamGobbler(name, is, out, size); } catch (IllegalArgumentException e) { log.error(e.getMessage()); size = 8192; /* retry with default */ }

Prevention

When it happens

Trigger: 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.

Common situations: Configuration files with buffer size 0 or missing values defaulting to 0; calculations like (maxSize / numThreads) truncating to 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/11e84acd5e1f9da0. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/ByteStreamGobbler.java:32

  int bufferSize = 4096;

  public ByteStreamGobbler(InputStream is, OutputStream out) {
    this.inStream = new BufferedInputStream(is);
    this.outStream = new BufferedOutputStream(out);
  }

  public ByteStreamGobbler(String name, InputStream is, OutputStream out) {
    super(name);
    this.inStream = new BufferedInputStream(is);
    this.outStream = new BufferedOutputStream(out);
  }

  public ByteStreamGobbler(String name, InputStream is, OutputStream out, int bufferSize) {
    super(name);
    this.inStream = new BufferedInputStream(is);
    this.outStream = new BufferedOutputStream(out);
    if (bufferSize <= 0) {
      throw new IllegalArgumentException("Invalid buffer size " + bufferSize + ": must be larger than 0");
    }
    this.bufferSize = bufferSize;
  }

  public InputStream getInputStream()
  {
    return inStream;
  }

  public OutputStream getOutputStream()
  {
    return outStream;
  }

  public void run() {
    try {
      byte[] b = new byte[bufferSize];
      int bytesRead;

View on GitHub (pinned to 1b7edd19c4)