{"record":{"id":"df4a62bef7433847","repo":"stanfordnlp/CoreNLP","slug":"slurpfile-io-problem","errorCode":null,"errorMessage":"slurpFile IO problem","messagePattern":"slurpFile IO problem","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1192,"sourceCode":"   */\n  public static String slurpFile(String filename, String encoding)\n          throws IOException {\n    Reader r = readerFromString(filename, encoding);\n    return IOUtils.slurpReader(r);\n  }\n\n  /**\n   * Returns all the text in the given file with the given\n   * encoding. If the file cannot be read (non-existent, etc.), then\n   * the method throws an unchecked RuntimeIOException.  If the caller\n   * is willing to tolerate missing files, they should catch that\n   * exception.\n   */\n  public static String slurpFileNoExceptions(String filename, String encoding) {\n    try {\n      return slurpFile(filename, encoding);\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"slurpFile IO problem\", e);\n    }\n  }\n\n  /**\n   * Returns all the text in the given file\n   *\n   * @return The text in the file.\n   */\n  public static String slurpFile(String filename) throws IOException {\n    return slurpFile(filename, defaultEncoding);\n  }\n\n  /**\n   * Returns all the text at the given URL.\n   */\n  public static String slurpURLNoExceptions(URL u, String encoding) {\n    try {\n      return IOUtils.slurpURL(u, encoding);","sourceCodeStart":1174,"sourceCodeEnd":1210,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1174-L1210","documentation":"slurpFileNoExceptions() wraps failures of slurpFile(filename, encoding) in a RuntimeIOException with message \"slurpFile IO problem\". It is thrown when reading the entire text of a file fails with an IOException (missing file, unreadable file, wrong encoding, etc.). The original IOException is chained as the cause, so check getCause() for the real reason.","triggerScenarios":"Calling IOUtils.slurpFileNoExceptions(filename, encoding) when slurpFile throws: the file does not exist, the path is a directory, the process lacks read permission, the stream cannot be opened, or the reader/decoder fails due to an invalid or unsupported encoding.","commonSituations":"Config files or corpus files specified with a wrong path or relative path resolved against an unexpected working directory; typo'd charset name (e.g. \"utf8\" typos are usually fine but \"UTF_8\" is not); files deleted or moved between existence-check and read; running as a user without read permission.","solutions":["Verify the file path exists and is readable: new File(path).canRead() before calling, or print new File(path).getAbsolutePath() to check path resolution.","Inspect e.getCause() (the chained IOException) to see the underlying reason (FileNotFoundException vs UnsupportedEncodingException).","Check the encoding string is a valid Java charset name, or use the File overload without encoding (defaults to UTF-8 in recent versions).","If you want the checked exception instead, call IOUtils.slurpFile(filename, encoding) directly and handle IOException."],"exampleFix":"// before\nString text = IOUtils.slurpFileNoExceptions(cfgPath, \"UTF-8\");\n// after\nFile f = new File(cfgPath);\nif (!f.isFile() || !f.canRead()) {\n  throw new IllegalArgumentException(\"Cannot read config: \" + f.getAbsolutePath());\n}\nString text = IOUtils.slurpFileNoExceptions(f, StandardCharsets.UTF_8.name());","handlingStrategy":"try-catch","validationCode":"File f = new File(path);\nif (!f.isFile()) throw new IllegalStateException(\"Not a file: \" + f.getAbsolutePath());\nif (!f.canRead()) throw new IllegalStateException(\"Not readable: \" + f.getAbsolutePath());\nCharset.forName(encoding); // validate charset name","typeGuard":null,"tryCatchPattern":"try {\n  String text = IOUtils.slurpFileNoExceptions(f, encoding);\n} catch (RuntimeIOException e) {\n  throw new IOException(\"Failed to slurp \" + f.getAbsolutePath() + \": \" + e.getCause(), e.getCause());\n}","preventionTips":["Always print/log getAbsolutePath() when a read fails — relative paths resolve against the process CWD.","Validate the encoding string with Charset.forName() at startup.","Prefer the checked IOUtils.slurpFile if you need to handle missing files explicitly."],"tags":["io","file-read","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"}