stanfordnlp/CoreNLP · error · RuntimeIOException
slurpReader IO problem
Error message
slurpReader IO problem
What it means
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().
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.
Example fix
// before
String all = IOUtils.slurpReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
// after
try (Reader r = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)) {
String all = IOUtils.slurpReader(r);
} catch (RuntimeIOException e) {
logger.warn("slurpReader failed: " + e.getCause());
throw new IOException(e.getCause());
} Defensive patterns
Strategy: try-catch
Validate before calling
if (reader == null) throw new IllegalArgumentException("reader is null");
// ensure source stream is open and unread-from before wrapping Try / catch
try {
String text = IOUtils.slurpReader(reader);
} catch (RuntimeIOException e) {
Throwable cause = e.getCause();
throw new IOException("slurpReader failed on " + reader + ": " + cause, cause);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- slurpFile IO problem
- Error loading classifier from
- edu.stanford.nlp.io.RuntimeIOException
- Error creating data exporter
- Error reading saved links
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/90b4913cf4d6e34c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:1356
/**
* Returns all the text from the given Reader.
* Closes the Reader when done.
*
* @return The text in the file.
*/
public static String slurpReader(Reader reader) {
StringBuilder buff = new StringBuilder();
try (BufferedReader r = new BufferedReader(reader)) {
char[] chars = new char[SLURP_BUFFER_SIZE];
while (true) {
int amountRead = r.read(chars, 0, SLURP_BUFFER_SIZE);
if (amountRead < 0) {
break;
}
buff.append(chars, 0, amountRead);
}
} catch (Exception e) {
throw new RuntimeIOException("slurpReader IO problem", e);
}
return buff.toString();
}
/**
* Read the contents of an input stream, decoding it according to the given character encoding.
* @param input The input stream to read from
* @return The String representation of that input stream
*/
public static String slurpInputStream(InputStream input, String encoding) throws IOException {
return slurpReader(encodedInputStreamReader(input, encoding));
}
/**
* Send all bytes from the input stream to the output stream.
*
* @param input The input bytes.
* @param output Where the bytes should be written.View on GitHub (pinned to 1b7edd19c4)