stanfordnlp/CoreNLP · error · RuntimeIOException
Serializing classifier to
Error message
Serializing classifier to
What it means
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.
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.
Example fix
// before
props.setProperty("serializeTo", "models/mycrf.ser.gz"); // models/ missing -> RuntimeIOException
// after
new File("models").mkdirs();
props.setProperty("serializeTo", "models/mycrf.ser.gz"); Defensive patterns
Strategy: try-catch
Validate before calling
File out = new File(serializePath);
if (out.getParentFile() != null && !out.getParentFile().canWrite())
throw new IOException("Cannot write to " + out.getParentFile());
if (out.getParentFile() != null) out.getParentFile().mkdirs();
if (new File(serializePath).getUsableSpace() < 1_000_000_000L) throw new IOException("Low disk space"); Try / catch
try {
crf.serializeClassifierToString(serializePath);
} catch (RuntimeIOException e) {
Throwable cause = e.getCause();
log.error("Serialization failed for " + serializePath + ": " + cause, cause);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- Failed to save classifier
- Could not open temporary feature index file for reading.
- Failed to load segmenter
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1bf7ad5c9809f5e9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:2497
}
return f;
}
/**
* {@inheritDoc}
*/
@Override
public void serializeClassifier(String serializePath) {
ObjectOutputStream oos = null;
try {
oos = IOUtils.writeStreamFromString(serializePath);
serializeClassifier(oos);
log.info("Serializing classifier to " + serializePath + "... done.");
} catch (Exception e) {
throw new RuntimeIOException("Serializing classifier to " + serializePath + "... FAILED", e);
} finally {
IOUtils.closeIgnoringExceptions(oos);
}
}
/**
* Serialize the classifier to the given ObjectOutputStream.
* <br>
* (Since the classifier is a processor, we don't want to serialize the
* whole classifier but just the data that represents a classifier model.)
*/
@Override
public void serializeClassifier(ObjectOutputStream oos) {
try {
oos.writeObject(labelIndices);
oos.writeObject(classIndex);
oos.writeObject(featureIndex);
oos.writeObject(flags);View on GitHub (pinned to 1b7edd19c4)