stanfordnlp/CoreNLP · error · RuntimeClassNotFoundException
java.lang.ClassNotFoundException
Error message
java.lang.ClassNotFoundException
What it means
StatTokSent loads a serialized statistical sentence-splitting model via object deserialization (IOUtils.readStreamFromString then ColumnDataClassifier.getClassifier). If the class of an object stored in the serialized stream cannot be found on the classpath, the underlying ObjectInputStream throws ClassNotFoundException, which is wrapped in RuntimeClassNotFoundException at src/edu/stanford/nlp/process/stattok/StatTokSent.java:86. This means the model file was produced with classes (often from a different CoreNLP version) that are not present at runtime.
Solutions
- Add the CoreNLP jar version that matches the one used to train/serialize the model to the classpath.
- Verify the model file is complete and uncorrupted (re-download; check no shading/filtering stripped .class resources).
- Re-train or re-serialize the model with the CoreNLP version actually used at runtime.
- Check the full cause chain (RuntimeClassNotFoundException.getCause()) to identify the missing class name and add the artifact providing it.
Example fix
// before
StatTokSent sent = new StatTokSent("model.ser.gz"); // CNFE under wrong jar
// after (Maven: align versions)
// <dependency><groupId>edu.stanford.nlp</groupId><artifactId>stanford-corenlp</artifactId><version>4.5.7</version></dependency>
StatTokSent sent = new StatTokSent("model.ser.gz"); Defensive patterns
Strategy: try-catch
Validate before calling
Class.forName("edu.stanford.nlp.classify.ColumnDataClassifier"); // and verify jar version matches model's
// optionally: check new StatTokSent model jar presence
if (!new File("model.ser.gz").canRead()) throw new IllegalStateException("model missing"); Type guard
boolean modelLoadable(String path) {
return path != null && path.endsWith(".ser.gz") && new File(path).canRead();
} Try / catch
try {
StatTokSent s = new StatTokSent(modelFile);
} catch (RuntimeClassNotFoundException e) {
logger.severe("Missing class for model: " + e.getCause());
} Prevention
- Pin the CoreNLP version used for training and serving to the same release
- Never shade/ProGuard jars containing serialized model classes
- Run a smoke test that loads every model at startup
When it happens
Trigger: Calling new StatTokSent(modelFile) or StatTokSent.loadModel on a serialized model whose embedded classes (e.g. ColumnDataClassifier or feature classes) are missing from the classpath, typically after a CoreNLP version mismatch or running with a trimmed jar.
Common situations: Model trained with CoreNLP 3.x loaded under a different/older CoreNLP jar; running with only stanford-corenlp.jar but not the classifier model classes; fat jar built with classes stripped by ProGuard/shading.
Related errors
- Error loading classifier from
- Error leading weights from {modelFile}
- Should have FeatureFactory but got
- Failed to read lambdas from given input stream
- Invalid model at path: " + serializedModel
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3553f48c51f396ad.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/process/stattok/StatTokSent.java:86
} else {
logger.info("Using multi word rules from " + multiWordRulesFile);
try {
multiWordRules = this.readMultiWordRules(multiWordRulesFile);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
ObjectInputStream ois;
try {
ois = IOUtils.readStreamFromString(modelFile);
cdc = ColumnDataClassifier.getClassifier(ois);
this.windowSize = ois.readInt();
} catch (IOException e) {
throw new RuntimeIOException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeClassNotFoundException(e);
}
logger.info("Found window size of " + this.windowSize);
}
public StatTokSent(String modelFile) {
this(modelFile, null);
}
/**
* The file reader for multi-word tokens rules file
* The reader accept the following formatting:
* {@code <token>\t<part>,...,<part>}
*/
private Map<String, String[]> readMultiWordRules(String multiWordRulesFile) throws IOException {
Map<String, String[]> multiWordRules = new HashMap<String, String[]>();
View on GitHub (pinned to 1b7edd19c4)