stanfordnlp/CoreNLP · error · RuntimeIOException

RuntimeIOException wrapping IOException

Error message

RuntimeIOException wrapping IOException

What it means

SingletonPredictor.saveToSerialized writes the trained predictor to a file via ObjectOutputStream; any IOException is rethrown as RuntimeIOException. This is the library's idiomatic way of converting checked IO failures during model serialization into unchecked exceptions.

Solutions

  1. Ensure the target directory exists and is writable (mkdir -p, check permissions)
  2. Use a valid IOUtils filename string (prefix with gzip: if compression is desired; plain absolute path otherwise)
  3. Check disk space
  4. Catch RuntimeIOException at the call site if serialization is optional

Example fix

// before
predictor.saveToSerialized("model/singleton.predictor.ser");
// after
File out = new File("model");
if (!out.exists()) out.mkdirs();
predictor.saveToSerialized(out.getAbsolutePath() + "/singleton.predictor.ser");
Defensive patterns

Strategy: try-catch

Validate before calling

java.io.File f = new java.io.File(outPath);
java.io.File parent = f.getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs())
  throw new IllegalStateException("Cannot create output dir: " + parent);
if (parent != null && !parent.canWrite()) throw new IllegalStateException("Not writable: " + parent);

Try / catch

try {
  SingletonPredictor.saveToSerialized(path);
} catch (RuntimeIOException e) {
  log.error("Failed to save singleton predictor: " + e.getCause());
  throw e;
}

Prevention

When it happens

Trigger: Calling SingletonPredictor save/serialization code where opening the output stream (IOUtils.writeStreamFromString) or writeObject fails — bad path, unwritable location, or IO error mid-write.

Common situations: Output directory does not exist; path string in a format IOUtils cannot interpret (IOUtils.writeStreamFromString supports URL-like prefixes such as gzip:); disk full; no write permission.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/coref/misc/SingletonPredictor.java:155

    LogisticClassifier<String, String> classifier = lcf.trainClassifier(pDataset);

    return classifier;
  }

  /**
   * Saves the singleton predictor model to the given filename.
   * If there is an error, a RuntimeIOException is thrown.
   */
  private static void saveToSerialized(LogisticClassifier<String, String> predictor,
                                       String filename) {
    try {
      log.info("Writing singleton predictor in serialized format to file " + filename + ' ');
      ObjectOutputStream out = IOUtils.writeStreamFromString(filename);
      out.writeObject(predictor);
      out.close();
      log.info("done.");
    } catch (IOException ioe) {
      throw new RuntimeIOException(ioe);
    }
  }

  private static String getPathSingletonPredictor(Properties props) {
    return PropertiesUtils.getString(props, "coref.path.singletonPredictor", "edu/stanford/nlp/models/dcoref/singleton.predictor.ser");
  }

  public static void main(String[] args) throws Exception {
    Properties props;
    if (args.length > 0) {
      props = StringUtils.argsToProperties(args);
    } else {
      props = new Properties();
    }
    if ( ! props.containsKey("dcoref.conll2011")) {
      log.info("-dcoref.conll2011 [input_CoNLL_corpus]: was not specified");
      return;
    }

View on GitHub (pinned to 1b7edd19c4)