stanfordnlp/CoreNLP · error · RuntimeException

RuntimeException wrapping IOException

Error message

RuntimeException wrapping IOException

What it means

loadCorefDict reads tab-separated coref dictionary files and rethrows any IOException as an unchecked RuntimeException wrapping it. It means one of the coreference dictionary resources (e.g. Bergsma-Lin lists) could not be opened or read.

Solutions

  1. Verify each coref dictionary file path in the properties exists and is readable
  2. Ensure CoreNLP models jar is present on the classpath
  3. Use classpath:/ URLs for bundled resources
  4. Check file integrity (not truncated/empty) and permissions

Example fix

// before
props.setProperty("coref.dict1", "dict1.tsv"); // relative, wrong cwd
// after
props.setProperty("coref.dict1", "classpath:/edu/stanford/nlp/models/dcoref/dict1.txt");
Defensive patterns

Strategy: try-catch

Validate before calling

for (String key : new String[]{"coref.dict1","coref.dict2","coref.dict3","coref.dict4"}) {
    String v = props.getProperty(key);
    if (v != null && !IOUtils.existsInClasspathOrFileSystem(v)) {
        throw new IllegalStateException(key + " file not found: " + v);
    }
}

Try / catch

try {
    new Dictionaries(props);
} catch (RuntimeException e) {
    if (e.getCause() instanceof IOException) {
        log.error("Coref dict file unreadable: " + e.getCause().getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Constructing Dictionaries when any loadCorefDict input file path is wrong, the file is unreadable, or the stream throws while iterating reader.readLine().

Common situations: Missing CoreNLP models resources, misconfigured coref.dict.* properties, packaging that omits dictionary files, or permission/working-directory problems.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/a999f43233c27c77. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/dcoref/Dictionaries.java:418

  private static void loadCorefDict(String[] file,
      ArrayList<Counter<Pair<String, String>>> dict) {

    for(int i = 0; i < 4; i++){
      dict.add(new ClassicCounter<>());

      BufferedReader reader = null;
      try {
        reader = IOUtils.readerFromString(file[i]);
        // Skip the first line (header)
        reader.readLine();

        while(reader.ready()) {
          String[] split = reader.readLine().split("\t");
          dict.get(i).setCount(new Pair<>(split[0], split[1]), Double.parseDouble(split[2]));
        }

      } catch (IOException e) {
        throw new RuntimeException(e);
      } finally {
        IOUtils.closeIgnoringExceptions(reader);
      }
    }
  }

  private static void loadCorefDictPMI(String file, Counter<Pair<String, String>> dict) {

      BufferedReader reader = null;
      try {
        reader = IOUtils.readerFromString(file);
        // Skip the first line (header)
        reader.readLine();

        while(reader.ready()) {
          String[] split = reader.readLine().split("\t");
          dict.setCount(new Pair<>(split[0], split[1]), Double.parseDouble(split[3]));
        }

View on GitHub (pinned to 1b7edd19c4)