{"record":{"id":"2d7020e30bedf214","repo":"stanfordnlp/CoreNLP","slug":"s-could-not-open-path-s","errorCode":null,"errorMessage":"%s: Could not open path %s","messagePattern":"(.+?): Could not open path (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/DocumentPreprocessor.java","lineNumber":140,"sourceCode":"\n\n  /**\n   * Constructs a preprocessor from a file at a path, which can be either\n   * a filesystem location, a classpath entry, or a URL.\n   *\n   * @param docPath The path\n   * @param encoding The character encoding used by Readers\n   */\n  public DocumentPreprocessor(String docPath, DocType t, String encoding) {\n    if (docPath == null) {\n      throw new IllegalArgumentException(\"Cannot open null document path!\");\n    }\n\n    docType = t;\n    try {\n      inputReader = IOUtils.readerFromString(docPath, encoding);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(String.format(\"%s: Could not open path %s\", this.getClass().getName(), docPath),\n              ioe);\n    }\n  }\n\n  /**\n   * Set whether or not the tokenizer keeps empty sentences in\n   * whitespace mode.  Useful for programs that want to echo blank\n   * lines.  Not relevant for the non-whitespace model.\n   */\n  public void setKeepEmptySentences(boolean keepEmptySentences) {\n    this.keepEmptySentences = keepEmptySentences;\n  }\n\n  /**\n   * Sets the end-of-sentence delimiters.\n   * <p>\n   * For newline tokenization, use the argument {\"\\n\"}.\n   *","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/DocumentPreprocessor.java#L122-L158","documentation":"When the docPath is non-null but IOUtils.readerFromString(docPath, encoding) throws an IOException, the constructor rethrows it as a RuntimeIOException formatted as \"<ClassName>: Could not open path <path>\". This means the path could not be opened as a readable character stream — the file is missing, unreadable, or the encoding is invalid.","triggerScenarios":"Calling new DocumentPreprocessor(docPath, docType, encoding) with a path that does not exist, points to a directory, lacks read permission, has a malformed URL/file: syntax, or an unsupported encoding name.","commonSituations":"Typo'd or relative path resolved against the wrong working directory; file deleted or not yet generated; running in a container where the input volume is not mounted; unsupported charset string like \"utf8\" misspellings on strict JVMs.","solutions":["Verify the file exists and is readable: new File(docPath).canRead() before constructing","Use an absolute path or resolve relative paths against the intended base directory","Check the encoding string is a valid charset name (Charset.isSupported(encoding))","If the path is a classpath resource, load it via IOUtils.readerFromClassPath or getResourceAsStream instead","Catch RuntimeIOException around construction to surface the original IOException cause"],"exampleFix":"// before\nDocumentPreprocessor dp = new DocumentPreprocessor(\"data/input.txt\", DocType.Plain, \"UTF-8\");\n// after\nFile f = new File(\"data/input.txt\");\nif (!f.isFile() || !f.canRead()) {\n  throw new FileNotFoundException(\"Input not readable: \" + f.getAbsolutePath());\n}\nDocumentPreprocessor dp = new DocumentPreprocessor(f.getAbsolutePath(), DocType.Plain, \"UTF-8\");","handlingStrategy":"validation","validationCode":"File f = new File(docPath);\nif (!f.isFile()) throw new FileNotFoundException(\"Not a file: \" + f.getAbsolutePath());\nif (!f.canRead()) throw new IOException(\"No read permission: \" + f.getAbsolutePath());\nif (!Charset.isSupported(encoding)) throw new UnsupportedEncodingException(encoding);","typeGuard":null,"tryCatchPattern":"try {\n  DocumentPreprocessor dp = new DocumentPreprocessor(docPath, DocType.Plain, \"UTF-8\");\n} catch (RuntimeIOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Could not open path\")) {\n    throw new InputOpenException(\"Cannot open document: \" + docPath, e.getCause());\n  }\n  throw e;\n}","preventionTips":["Check canRead()/isFile() before constructing the preprocessor","Resolve relative paths against a known base directory and log the absolute path on failure","Validate charset names with Charset.isSupported","In containers, verify the input volume is mounted at the expected path"],"tags":["io","file","path","runtime-io-exception","file-not-found"],"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-16T04:17:20.429Z"}