{"record":{"id":"990952914f845df8","repo":"stanfordnlp/CoreNLP","slug":"stream-closed","errorCode":null,"errorMessage":"Stream Closed","messagePattern":"Stream Closed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/ReaderInputStream.java","lineNumber":75,"sourceCode":"  public ReaderInputStream(Reader reader, String encoding) {\n    this(reader);\n    if (encoding == null) {\n      throw new IllegalArgumentException(\"encoding must not be null\");\n    } else {\n      this.encoding = encoding;\n    }\n  }\n\n  /**\n   * Reads from the <CODE>Reader</CODE>, returning the same value.\n   *\n   * @return the value of the next character in the <CODE>Reader</CODE>.\n   *\n   * @exception IOException if the original <code>Reader</code> fails to be read\n   */\n  public synchronized int read() throws IOException {\n    if (in == null) {\n      throw new IOException(\"Stream Closed\");\n    }\n\n    byte result;\n    if (slack != null && begin < slack.length) {\n      result = slack[begin];\n      if (++begin == slack.length) {\n        slack = null;\n      }\n    } else {\n      byte[] buf = new byte[1];\n      if (read(buf, 0, 1) <= 0) {\n        result = -1;\n      }\n      result = buf[0];\n    }\n\n    if (result < -1) {\n      result += 256;","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/ReaderInputStream.java#L57-L93","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the stream is only read before close(); restructure code so reading happens inside the try block.","Check that the Reader passed to the constructor is not null before constructing.","If reuse is needed, create a new ReaderInputStream instead of reusing a closed one."],"exampleFix":"// before\nReaderInputStream in = new ReaderInputStream(reader);\nin.close();\nint b = in.read(); // IOException: Stream Closed\n// after\ntry (ReaderInputStream in = new ReaderInputStream(reader)) {\n  int b = in.read();\n}","handlingStrategy":"try-catch","validationCode":"if (in == null) throw new IllegalStateException(\"ReaderInputStream not yet open\");\n// else safe to call read()","typeGuard":null,"tryCatchPattern":"try {\n  int b = stream.read();\n} catch (IOException e) {\n  if (\"Stream Closed\".equals(e.getMessage())) {\n    throw new IllegalStateException(\"read() called on closed ReaderInputStream\", e);\n  }\n  throw e;\n}","preventionTips":["Use try-with-resources so all reads occur before close().","Never read a stream after its owning pipeline/finally block has closed it.","Don't store stream references in long-lived fields that outlive the close scope."],"tags":["io","stream-closed","input-stream","lifecycle"],"backgroundTag":"stream-closed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}