{"record":{"id":"159ef92e292bac96","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-load-classifier","errorCode":null,"errorMessage":"Couldn't load classifier!","messagePattern":"Couldn't load classifier!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/ClassifierCombiner.java","lineNumber":228,"sourceCode":"    // read in the base classifiers\n    int numClassifiers = ois.readInt();\n    // set up the list of base classifiers\n    this.baseClassifiers = new ArrayList<>();\n    int i = 0;\n    while (i < numClassifiers) {\n      try {\n        log.info(\"loading CRF...\");\n        CRFClassifier<IN> newCRF = ErasureUtils.uncheckedCast(CRFClassifier.getClassifier(ois, props));\n        baseClassifiers.add(newCRF);\n        i++;\n      } catch (Exception e) {\n        try {\n          log.info(\"loading CMM...\");\n          CMMClassifier newCMM = ErasureUtils.uncheckedCast(CMMClassifier.getClassifier(ois, props));\n          baseClassifiers.add(newCMM);\n          i++;\n        } catch (Exception ex) {\n          throw new IOException(\"Couldn't load classifier!\", ex);\n        }\n      }\n    }\n  }\n\n  /**\n   * Either finds COMBINATION_MODE_PROPERTY or returns a default value.\n   */\n  public static CombinationMode extractCombinationMode(Properties p) {\n    String mode = p.getProperty(COMBINATION_MODE_PROPERTY);\n    if (mode == null) {\n      return DEFAULT_COMBINATION_MODE;\n    } else {\n      return CombinationMode.valueOf(mode.toUpperCase(Locale.ROOT));\n    }\n  }\n\n  /**","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ClassifierCombiner.java#L210-L246","documentation":"ClassifierCombiner's ObjectInputStream-based constructor loads a sequence of base classifiers (CRF/CMM) from a stream. If deserializing a CMM classifier fails for any reason, the underlying exception is wrapped and rethrown as an IOException with this message.","triggerScenarios":"ClassifierCombiner.getClassifier(ObjectInputStream, Properties) is called with a stream that does not contain the expected serialized classifier, the stream is truncated/corrupt, or the classpath lacks classifier classes so deserialization throws.","commonSituations":"See trigger scenarios.","solutions":["Re-serialize the classifier files with the same Stanford CoreNLP version you use at load time","Verify the InputStream actually points at the correct classifier resource (check path/order of classifiers in the properties)","Inspect the wrapped cause 'ex' to see the true deserialization failure","Confirm all Stanford NLP jars on the classpath are the same version"],"exampleFix":"// before: mismatched versions\nClassifierCombiner c = new ClassifierCombiner(ois, props); // IOException: Couldn't load classifier!\n// after: rebuild classifiers with matching jar version\n// mvn dependency: on edu.stanford.nlp:stanford-corenlp:3.9.2 everywhere, then\nClassifierCombiner c = new ClassifierCombiner(ois, props);","handlingStrategy":"try-catch","validationCode":"// verify resource exists and stream is non-empty before loading\ntry (InputStream in = new FileInputStream(classifierFile)) {\n  if (in.read() == -1) throw new IllegalStateException(\"empty classifier file\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  ClassifierCombiner c = new ClassifierCombiner(ois, props);\n} catch (IOException e) {\n  log.error(\"classifier load failed; check version match and stream integrity\", e.getCause());\n  throw new UncheckedIOException(e);\n}","preventionTips":["Pin all Stanford CoreNLP jars to one version","Re-serialize classifiers with the same library version you load with","Verify classifier files are on the classpath / deployed"],"tags":["java","corenlp","deserialization","classifier"],"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"}