stanfordnlp/CoreNLP · error · RuntimeIOException
Failed to save classifier
Error message
Failed to save classifier
What it means
serializeClassifier(String) opens an output stream via IOUtils.writeStreamFromString and writes the combined classifier. Any failure during opening the stream or writing the model is wrapped as a RuntimeIOException with this message.
Solutions
- Create parent directories before serializing: new File(path).getParentFile().mkdirs()
- Verify write permission on the target path for the running user
- Serialize to a local writable path first, then copy to the final destination
- Check the wrapped cause for the underlying IO failure
Example fix
// before
classifier.serializeClassifier("out/models/model.ser.gz"); // RuntimeIOException if out/models missing
// after
new File("out/models").mkdirs();
classifier.serializeClassifier("out/models/model.ser.gz"); Defensive patterns
Strategy: try-catch
Validate before calling
File out = new File(path);
File parent = out.getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs())
throw new IllegalStateException("cannot create dir " + parent);
if (parent != null && !parent.canWrite()) throw new IllegalStateException("not writable: " + parent); Try / catch
try {
classifier.serializeClassifier(serializePath);
} catch (RuntimeIOException e) {
log.error("model save failed", e.getCause());
throw e;
} Prevention
- mkdirs() parent directories before serializing
- Serialize to temp file then atomic rename
- Run serialization under a user with write access to the target dir
When it happens
Trigger: Calling classifier.serializeClassifier("/bad/dir/model.ser.gz") where the target directory does not exist, is not writable, or the path string is not a valid filename/URL for IOUtils.writeStreamFromString.
Common situations: Writing to a read-only deployment directory; missing parent directories; running under a user without write permission; disk full during model dump.
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
- RuntimeIOException wrapping IOException
- Error creating data exporter
- RuntimeException with no message (model write failure)
- Serializing classifier to
- ERROR: Invalid dependency node line
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/7b53cac329bdaaeb.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/ClassifierCombiner.java:504
@Override
public void train(Collection<List<IN>> docs,
DocumentReaderAndWriter<IN> readerAndWriter) {
throw new UnsupportedOperationException();
}
// write a ClassifierCombiner to disk, this is based on CRFClassifier code
@Override
public void serializeClassifier(String serializePath) {
log.info("Serializing classifier to " + serializePath + "...");
ObjectOutputStream oos = null;
try {
oos = IOUtils.writeStreamFromString(serializePath);
serializeClassifier(oos);
log.info("done.");
} catch (Exception e) {
throw new RuntimeIOException("Failed to save classifier", e);
} finally {
IOUtils.closeIgnoringExceptions(oos);
}
}
// method for writing a ClassifierCombiner to an ObjectOutputStream
@Override
public void serializeClassifier(ObjectOutputStream oos) {
try {
// record the properties used to initialize
oos.writeObject(initProps);
// this is a bit of a hack, but have to write this twice so you can get it again
// after you initialize AbstractSequenceClassifier
// basically when this is read from the ObjectInputStream, I read it once to call
// super(props) and then I read it again so I can set this.initProps
// TODO: probably should have AbstractSequenceClassifier store initProps to get rid of this double writing
oos.writeObject(initProps);
// record the initial loadPathsView on GitHub (pinned to 1b7edd19c4)