{"record":{"id":"3553f48c51f396ad","repo":"stanfordnlp/CoreNLP","slug":"java-lang-classnotfoundexception","errorCode":null,"errorMessage":"java.lang.ClassNotFoundException","messagePattern":"java\\.lang\\.ClassNotFoundException","errorType":"exception","errorClass":"RuntimeClassNotFoundException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/stattok/StatTokSent.java","lineNumber":86,"sourceCode":"    } else {\n      logger.info(\"Using multi word rules from \" + multiWordRulesFile);\n      try {\n        multiWordRules = this.readMultiWordRules(multiWordRulesFile);\n      } catch (IOException e) {\n        throw new RuntimeIOException(e);\n      }\n    }\n\n    ObjectInputStream ois;\n\n    try {\n      ois = IOUtils.readStreamFromString(modelFile);\n      cdc = ColumnDataClassifier.getClassifier(ois);\n      this.windowSize = ois.readInt();\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    } catch (ClassNotFoundException e) {\n      throw new RuntimeClassNotFoundException(e);\n    }\n\n    logger.info(\"Found window size of \" + this.windowSize);\n  }\n\n  public StatTokSent(String modelFile) {\n    this(modelFile, null);\n  }\n\n\n  /**\n   * The file reader for multi-word tokens rules file\n   * The reader accept the following formatting:\n   * {@code <token>\\t<part>,...,<part>}\n   */\n  private Map<String, String[]> readMultiWordRules(String multiWordRulesFile) throws IOException {\n    Map<String, String[]> multiWordRules = new HashMap<String, String[]>();\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/stattok/StatTokSent.java#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nStatTokSent sent = new StatTokSent(\"model.ser.gz\"); // CNFE under wrong jar\n// after (Maven: align versions)\n// <dependency><groupId>edu.stanford.nlp</groupId><artifactId>stanford-corenlp</artifactId><version>4.5.7</version></dependency>\nStatTokSent sent = new StatTokSent(\"model.ser.gz\");","handlingStrategy":"try-catch","validationCode":"Class.forName(\"edu.stanford.nlp.classify.ColumnDataClassifier\"); // and verify jar version matches model's\n// optionally: check new StatTokSent model jar presence\nif (!new File(\"model.ser.gz\").canRead()) throw new IllegalStateException(\"model missing\");","typeGuard":"boolean modelLoadable(String path) {\n  return path != null && path.endsWith(\".ser.gz\") && new File(path).canRead();\n}","tryCatchPattern":"try {\n  StatTokSent s = new StatTokSent(modelFile);\n} catch (RuntimeClassNotFoundException e) {\n  logger.severe(\"Missing class for model: \" + e.getCause());\n}","preventionTips":["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"],"tags":["java","deserialization","classpath","model-loading"],"backgroundTag":"class-not-found","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"}