{"record":{"id":"cc10f50ff031ada3","repo":"stanfordnlp/CoreNLP","slug":"runtimeioexception-wrapping-ioexception","errorCode":null,"errorMessage":"RuntimeIOException wrapping IOException","messagePattern":"RuntimeIOException wrapping IOException","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/misc/SingletonPredictor.java","lineNumber":155,"sourceCode":"    LogisticClassifier<String, String> classifier = lcf.trainClassifier(pDataset);\n\n    return classifier;\n  }\n\n  /**\n   * Saves the singleton predictor model to the given filename.\n   * If there is an error, a RuntimeIOException is thrown.\n   */\n  private static void saveToSerialized(LogisticClassifier<String, String> predictor,\n                                       String filename) {\n    try {\n      log.info(\"Writing singleton predictor in serialized format to file \" + filename + ' ');\n      ObjectOutputStream out = IOUtils.writeStreamFromString(filename);\n      out.writeObject(predictor);\n      out.close();\n      log.info(\"done.\");\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(ioe);\n    }\n  }\n\n  private static String getPathSingletonPredictor(Properties props) {\n    return PropertiesUtils.getString(props, \"coref.path.singletonPredictor\", \"edu/stanford/nlp/models/dcoref/singleton.predictor.ser\");\n  }\n\n  public static void main(String[] args) throws Exception {\n    Properties props;\n    if (args.length > 0) {\n      props = StringUtils.argsToProperties(args);\n    } else {\n      props = new Properties();\n    }\n    if ( ! props.containsKey(\"dcoref.conll2011\")) {\n      log.info(\"-dcoref.conll2011 [input_CoNLL_corpus]: was not specified\");\n      return;\n    }","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/misc/SingletonPredictor.java#L137-L173","documentation":"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.","triggerScenarios":"Calling SingletonPredictor save/serialization code where opening the output stream (IOUtils.writeStreamFromString) or writeObject fails — bad path, unwritable location, or IO error mid-write.","commonSituations":"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.","solutions":["Ensure the target directory exists and is writable (mkdir -p, check permissions)","Use a valid IOUtils filename string (prefix with gzip: if compression is desired; plain absolute path otherwise)","Check disk space","Catch RuntimeIOException at the call site if serialization is optional"],"exampleFix":"// before\npredictor.saveToSerialized(\"model/singleton.predictor.ser\");\n// after\nFile out = new File(\"model\");\nif (!out.exists()) out.mkdirs();\npredictor.saveToSerialized(out.getAbsolutePath() + \"/singleton.predictor.ser\");","handlingStrategy":"try-catch","validationCode":"java.io.File f = new java.io.File(outPath);\njava.io.File parent = f.getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs())\n  throw new IllegalStateException(\"Cannot create output dir: \" + parent);\nif (parent != null && !parent.canWrite()) throw new IllegalStateException(\"Not writable: \" + parent);","typeGuard":null,"tryCatchPattern":"try {\n  SingletonPredictor.saveToSerialized(path);\n} catch (RuntimeIOException e) {\n  log.error(\"Failed to save singleton predictor: \" + e.getCause());\n  throw e;\n}","preventionTips":["Create output directories before saving models","Use plain absolute paths (or valid IOUtils filename prefixes like gzip:)","Monitor disk space on model-output volumes","Catch RuntimeIOException wherever model saving is not the critical path"],"tags":["java","corenlp","serialization","file-write"],"backgroundTag":"file-write-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"}