stanfordnlp/CoreNLP · error · IOException

Stream Closed

Error message

Stream Closed

What it means

ReaderInputStream.read() throws IOException("Stream Closed") when the underlying Reader field is null, which happens after close() or when the stream was never fully initialized. Any read attempt on a closed or unopened adapter fails with this sentinel message.

Solutions

  1. Ensure the stream is only read before close(); restructure code so reading happens inside the try block.
  2. Check that the Reader passed to the constructor is not null before constructing.
  3. If reuse is needed, create a new ReaderInputStream instead of reusing a closed one.

Example fix

// before
ReaderInputStream in = new ReaderInputStream(reader);
in.close();
int b = in.read(); // IOException: Stream Closed
// after
try (ReaderInputStream in = new ReaderInputStream(reader)) {
  int b = in.read();
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (in == null) throw new IllegalStateException("ReaderInputStream not yet open");
// else safe to call read()

Try / catch

try {
  int b = stream.read();
} catch (IOException e) {
  if ("Stream Closed".equals(e.getMessage())) {
    throw new IllegalStateException("read() called on closed ReaderInputStream", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling read() after close() set the internal reader to null; or reading an instance that was constructed with a null reader (the this(reader) path leaves in null).

Common situations: Double-closing streams in finally blocks; using a stream after a try-with-resources scope ended; constructing with a reader that was itself null from a failed resource lookup.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/io/ReaderInputStream.java:75

  public ReaderInputStream(Reader reader, String encoding) {
    this(reader);
    if (encoding == null) {
      throw new IllegalArgumentException("encoding must not be null");
    } else {
      this.encoding = encoding;
    }
  }

  /**
   * Reads from the <CODE>Reader</CODE>, returning the same value.
   *
   * @return the value of the next character in the <CODE>Reader</CODE>.
   *
   * @exception IOException if the original <code>Reader</code> fails to be read
   */
  public synchronized int read() throws IOException {
    if (in == null) {
      throw new IOException("Stream Closed");
    }

    byte result;
    if (slack != null && begin < slack.length) {
      result = slack[begin];
      if (++begin == slack.length) {
        slack = null;
      }
    } else {
      byte[] buf = new byte[1];
      if (read(buf, 0, 1) <= 0) {
        result = -1;
      }
      result = buf[0];
    }

    if (result < -1) {
      result += 256;

View on GitHub (pinned to 1b7edd19c4)