stanfordnlp/CoreNLP · error · RuntimeIOException

RuntimeIOException

Error message

RuntimeIOException

What it means

RuntimeIOException (a RuntimeException wrapper) is thrown when reading the serialized singleton predictor model file fails with an IOException — e.g. the file cannot be opened, is missing, or I/O fails mid-read. It surfaces IO problems from IOUtils.readStreamFromString / ObjectInputStream as an unchecked exception.

Solutions

  1. Check the model file path exists and is readable (ls / canRead)
  2. Correct the singletonModel (or equivalent) property to the right resource path
  3. Regenerate or re-download the model file if it is truncated/corrupt
  4. Catch RuntimeIOException around model loading to give a clearer user-facing error

Example fix

// before
SingletonPredictor predictor = SieveCoreferenceSystem.loadSingletonPredictor("models/single.ser");
// after
File f = new File("models/single.ser");
if (!f.exists() || !f.canRead()) throw new IllegalArgumentException("Missing singleton model: " + f);
SingletonPredictor predictor = SieveCoreferenceSystem.loadSingletonPredictor(f.getPath());
Defensive patterns

Strategy: try-catch

Validate before calling

File f = new File(path);
if (!f.exists()) throw new FileNotFoundException("Singleton model missing: " + path);
if (!f.canRead()) throw new IOException("No read permission: " + path);

Try / catch

try {
  SingletonPredictor p = SieveCoreferenceSystem.loadSingletonPredictor(path);
} catch (RuntimeIOException e) {
  throw new IllegalStateException("Failed to load singleton predictor model at " + path, e);
}

Prevention

When it happens

Trigger: Calling the singleton predictor loader with a serializedFile path that does not exist, is not readable, is a directory, or whose stream errors during deserialization.

Common situations: Wrong model path in dcoref properties; model file not shipped/downloaded; running from a jar/resource path that doesn't resolve; permission problems on the model file.

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/5a2a98c60d14bf5b. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java:1045

    }
    for (int removeId : removeClusterSet){
      document.corefClusters.remove(removeId);
    }
    for(Mention m : removeSet){
      document.positions.remove(m);
    }
  }

  public static LogisticClassifier<String, String> getSingletonPredictorFromSerializedFile(String serializedFile) {
    try {
      ObjectInputStream ois = IOUtils.readStreamFromString(serializedFile);
      Object o = ois.readObject();
      if (o instanceof LogisticClassifier<?, ?>) {
        return (LogisticClassifier<String, String>) o;
      }
      throw new ClassCastException("Wanted SingletonPredictor, got " + o.getClass());
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
  }

  /** Remove singleton clusters */
  public static List<List<Mention>> filterMentionsWithSingletonClusters(Document document, List<List<Mention>> mentions)
  {

    List<List<Mention>> res = new ArrayList<>(mentions.size());
    for (List<Mention> ml:mentions) {
      List<Mention> filtered = new ArrayList<>();
      for (Mention m:ml) {
        CorefCluster cluster = document.corefClusters.get(m.corefClusterID);
        if (cluster != null && cluster.getCorefMentions().size() > 1) {
          filtered.add(m);
        }
      }

View on GitHub (pinned to 1b7edd19c4)