{"record":{"id":"90b4913cf4d6e34c","repo":"stanfordnlp/CoreNLP","slug":"slurpreader-io-problem","errorCode":null,"errorMessage":"slurpReader IO problem","messagePattern":"slurpReader IO problem","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1356,"sourceCode":"  /**\n   * Returns all the text from the given Reader.\n   * Closes the Reader when done.\n   *\n   * @return The text in the file.\n   */\n  public static String slurpReader(Reader reader) {\n    StringBuilder buff = new StringBuilder();\n    try (BufferedReader r = new BufferedReader(reader)) {\n      char[] chars = new char[SLURP_BUFFER_SIZE];\n      while (true) {\n        int amountRead = r.read(chars, 0, SLURP_BUFFER_SIZE);\n        if (amountRead < 0) {\n          break;\n        }\n        buff.append(chars, 0, amountRead);\n      }\n    } catch (Exception e) {\n      throw new RuntimeIOException(\"slurpReader IO problem\", e);\n    }\n    return buff.toString();\n  }\n\n  /**\n   * Read the contents of an input stream, decoding it according to the given character encoding.\n   * @param input The input stream to read from\n   * @return The String representation of that input stream\n   */\n  public static String slurpInputStream(InputStream input, String encoding) throws IOException {\n    return slurpReader(encodedInputStreamReader(input, encoding));\n  }\n\n  /**\n   * Send all bytes from the input stream to the output stream.\n   *\n   * @param input The input bytes.\n   * @param output Where the bytes should be written.","sourceCodeStart":1338,"sourceCodeEnd":1374,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1338-L1374","documentation":"slurpReader(Reader) reads all text from a Reader into a string; any Exception raised during reading (including IOException from the underlying stream) is rethrown as a RuntimeIOException with message \"slurpReader IO problem\". It is a convenience wrapper that converts checked exceptions into runtime ones, keeping the cause available via getCause().","triggerScenarios":"Calling IOUtils.slurpReader(reader) where the underlying Reader throws while reading: a closed stream, a socket/pipe that broke mid-read, a corrupt Reader (e.g. InputStreamReader over a stream with invalid bytes for the declared charset), or an interrupted read.","commonSituations":"Slurping from a network stream or process stdout that was closed early (broken pipe); reusing a Reader that was already consumed/closed; decoding bytes with the wrong charset so the decoder throws; reading from a temporary file that was deleted while open.","solutions":["Check e.getCause() to identify the underlying read failure and fix at its source (stream closed? charset wrong?).","Ensure the Reader is open and not already fully consumed before passing it to slurpReader.","If reading a socket/process stream, handle partial reads yourself or increase timeouts rather than slurping all at once.","If the input may be corrupt/invalid bytes, wrap the source stream in a lenient decoder (e.g. InputStreamReader with CodingErrorAction.REPLACE) before slurping."],"exampleFix":"// before\nString all = IOUtils.slurpReader(new InputStreamReader(conn.getInputStream(), \"UTF-8\"));\n// after\ntry (Reader r = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)) {\n  String all = IOUtils.slurpReader(r);\n} catch (RuntimeIOException e) {\n  logger.warn(\"slurpReader failed: \" + e.getCause());\n  throw new IOException(e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"if (reader == null) throw new IllegalArgumentException(\"reader is null\");\n// ensure source stream is open and unread-from before wrapping","typeGuard":null,"tryCatchPattern":"try {\n  String text = IOUtils.slurpReader(reader);\n} catch (RuntimeIOException e) {\n  Throwable cause = e.getCause();\n  throw new IOException(\"slurpReader failed on \" + reader + \": \" + cause, cause);\n}","preventionTips":["Use try-with-resources so Readers are never half-closed mid-read.","Never reuse an already-consumed Reader; slurp exactly once.","For sockets/processes, check stream liveness or use timeouts instead of slurping everything."],"tags":["io","reader","java","runtime-exception"],"backgroundTag":"file-read-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}