{"record":{"id":"5cf96f442da8ea64","repo":"stanfordnlp/CoreNLP","slug":"runtimeioexception-5cf96f","errorCode":null,"errorMessage":"RuntimeIOException","messagePattern":"RuntimeIOException","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/dcoref/SingletonPredictor.java","lineNumber":150,"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  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    }\n    if ( ! props.containsKey(\"singleton.predictor.output\")) {\n      log.info(\"-singleton.predictor.output [output_model_file]: was not specified\");\n      return;\n    }","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/dcoref/SingletonPredictor.java#L132-L168","documentation":"SingletonPredictor.saveToSerialized wraps any IOException that occurs while opening or writing the ObjectOutputStream for the model file in a RuntimeIOException and rethrows it. This converts a checked I/O failure during model persistence into an unchecked exception.","triggerScenarios":"Calling SingletonPredictor.saveToSerialized(filename) when the output path cannot be opened (bad path, unwritable directory, invalid URL-style resource specification via IOUtils.writeStreamFromString) or the write itself fails (disk full, stream closed).","commonSituations":"Saving trained predictor to a nonexistent directory; lacking write permissions; typos in the output filename/resource string; disk quota exceeded during training pipelines.","solutions":["Ensure the target directory exists and is writable before calling saveToSerialized","Use a plain writable file path rather than an invalid IOUtils resource string","Check disk space/quota if the failure occurs mid-write","Catch RuntimeIOException to translate it into a clear save-failure message"],"exampleFix":"// before\npredictor.saveToSerialized(\"out/singleton.ser\");\n// after\nnew File(\"out\").mkdirs();\npredictor.saveToSerialized(\"out/singleton.ser\");","handlingStrategy":"try-catch","validationCode":"File out = new File(filename);\nFile parent = out.getAbsoluteFile().getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs()) throw new IOException(\"Cannot create dir \" + parent);\nif (out.exists() && !out.canWrite()) throw new IOException(\"Not writable: \" + out);","typeGuard":null,"tryCatchPattern":"try {\n  predictor.saveToSerialized(filename);\n} catch (RuntimeIOException e) {\n  log.severe(\"Saving singleton predictor failed: \" + e.getCause());\n  throw e;\n}","preventionTips":["Create output directories before saving models","Check disk space before long training jobs","Use absolute, writable paths for model output","Wrap save calls so I/O failures surface with context"],"tags":["java","ioexception","file-write","dcoref"],"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"}