{"record":{"id":"1bf7ad5c9809f5e9","repo":"stanfordnlp/CoreNLP","slug":"serializing-classifier-to","errorCode":null,"errorMessage":"Serializing classifier to ","messagePattern":"Serializing classifier to ","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":2497,"sourceCode":"    }\n\n    return f;\n  }\n\n\n  /**\n   * {@inheritDoc}\n   */\n  @Override\n  public void serializeClassifier(String serializePath) {\n    ObjectOutputStream oos = null;\n    try {\n      oos = IOUtils.writeStreamFromString(serializePath);\n      serializeClassifier(oos);\n      log.info(\"Serializing classifier to \" + serializePath + \"... done.\");\n\n    } catch (Exception e) {\n      throw new RuntimeIOException(\"Serializing classifier to \" + serializePath + \"... FAILED\", e);\n    } finally {\n      IOUtils.closeIgnoringExceptions(oos);\n    }\n  }\n\n  /**\n   * Serialize the classifier to the given ObjectOutputStream.\n   * <br>\n   * (Since the classifier is a processor, we don't want to serialize the\n   * whole classifier but just the data that represents a classifier model.)\n   */\n  @Override\n  public void serializeClassifier(ObjectOutputStream oos) {\n    try {\n      oos.writeObject(labelIndices);\n      oos.writeObject(classIndex);\n      oos.writeObject(featureIndex);\n      oos.writeObject(flags);","sourceCodeStart":2479,"sourceCodeEnd":2515,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L2479-L2515","documentation":"When serializeClassifierToString / the serializePath path fails (any Exception from opening the output stream or serializing the classifier), CRFClassifier wraps the cause in a RuntimeIOException with message 'Serializing classifier to <path>... FAILED'. The saved snippet shows the success log; the throw is the failure branch of the same call.","triggerScenarios":"Calling serializeClassifierToString(serializePath) or flags.serializeTo with a path/filename spec IOUtils cannot open (bad URL/file form, unwritable directory, nonexistent parent dir, invalid endpoint), or when serializeClassifier itself throws during object graph writing.","commonSituations":"Output directory does not exist or is not writable; serializeTo path uses an unsupported protocol string; disk full; serialization fails on a non-serializable component; running under a user without write permission.","solutions":["Ensure the serializeTo target's parent directory exists and is writable (mkdir -p, chmod).","Check the serializePath string format expected by IOUtils.writeStreamFromString (plain file path, or qualified with a supported handler prefix).","Read the chained cause exception (e.getCause()) to see the underlying IOException and fix it (permissions, disk space).","Verify disk space/quota before serializing large CRF models.","Call serializeClassifier(OutputStream) directly with your own FileOutputStream to get clearer IO errors."],"exampleFix":"// before\nprops.setProperty(\"serializeTo\", \"models/mycrf.ser.gz\"); // models/ missing -> RuntimeIOException\n// after\nnew File(\"models\").mkdirs();\nprops.setProperty(\"serializeTo\", \"models/mycrf.ser.gz\");","handlingStrategy":"try-catch","validationCode":"File out = new File(serializePath);\nif (out.getParentFile() != null && !out.getParentFile().canWrite())\n  throw new IOException(\"Cannot write to \" + out.getParentFile());\nif (out.getParentFile() != null) out.getParentFile().mkdirs();\nif (new File(serializePath).getUsableSpace() < 1_000_000_000L) throw new IOException(\"Low disk space\");","typeGuard":null,"tryCatchPattern":"try {\n  crf.serializeClassifierToString(serializePath);\n} catch (RuntimeIOException e) {\n  Throwable cause = e.getCause();\n  log.error(\"Serialization failed for \" + serializePath + \": \" + cause, cause);\n  throw e;\n}","preventionTips":["Always mkdirs() the output directory before serializing.","Check writable permissions and disk space for large models.","Always read the chained cause of RuntimeIOException.","Prefer serializeClassifier(OutputStream) for direct control over IO errors."],"tags":["java","io","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"}