{"record":{"id":"3e9c2d5d0734a52e","repo":"stanfordnlp/CoreNLP","slug":"classifier-class-not-found-problem","errorCode":null,"errorMessage":"Classifier class not found problem.","messagePattern":"Classifier class not found problem\\.","errorType":"http","errorClass":"javax.servlet.ServletException","httpStatus":500,"severity":"critical","filePath":"src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java","lineNumber":88,"sourceCode":"      String filename = \"/WEB-INF/data/models/\" + classifier;\n      InputStream is = getServletConfig().getServletContext().getResourceAsStream(filename);\n\n      if (is == null) {\n        throw new ServletException(\"File not found. Filename = \" + filename);\n      }\n      try {\n        if (filename.endsWith(\".gz\")) {\n          is = new BufferedInputStream(new GZIPInputStream(is));\n        } else {\n          is = new BufferedInputStream(is);\n        }\n        model = CRFClassifier.getClassifier(is);\n      } catch (IOException e) {\n        throw new ServletException(\"IO problem reading classifier.\");\n      } catch (ClassCastException e) {\n        throw new ServletException(\"Classifier class casting problem.\");\n      } catch (ClassNotFoundException e) {\n        throw new ServletException(\"Classifier class not found problem.\");\n      } finally {\n        IOUtils.closeIgnoringExceptions(is);\n      }\n      ners.put(classifier, model);\n    }\n  }\n\n  @Override\n  public void doGet(HttpServletRequest request, HttpServletResponse response)\n    throws ServletException, IOException\n  {\n    if (request.getCharacterEncoding() == null) {\n      request.setCharacterEncoding(\"utf-8\");\n    }\n    response.setContentType(\"text/html; charset=UTF-8\");\n\n    this.getServletContext().getRequestDispatcher(\"/header.jsp\").\n      include(request, response);","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java#L70-L106","documentation":"CRFClassifier.getClassifier(is) resolves classes while deserializing the model; if a class referenced by the serialized stream cannot be found on the servlet's classpath, a ClassNotFoundException is caught and rethrown as this ServletException. It means the classifier file references classes (CoreNLP classes or custom feature classes) missing from the deployed WAR.","triggerScenarios":"Servlet init with a serialized classifier whose classes are absent — e.g. models jar not on classpath, a model serialized with custom feature factories not shipped in the WAR, or a model from a newer CoreNLP referencing classes the old jar lacks.","commonSituations":"Deploying the WAR without the stanford-corenlp-x.y.z-models jar, upgrading CoreNLP jars but keeping old models (or vice versa), or shipping a classifier trained with custom code excluded from the build.","solutions":["Add the matching Stanford CoreNLP models jar (same version as the CoreNLP jar) to WEB-INF/lib or the servlet container's shared classpath.","Align CoreNLP and models jar versions exactly (e.g. corenlp 4.5.x jar + 4.5.x models).","If the model was trained with custom classes, package those classes in the WAR.","Inspect the ClassNotFoundException's class name in the cause chain to identify the missing jar."],"exampleFix":"// before: only corenlp jar deployed\ncp stanford-corenlp-4.5.4.jar WEB-INF/lib/\n// after: also deploy matching models jar\ncp stanford-corenlp-4.5.4.jar stanford-corenlp-4.5.4-models.jar WEB-INF/lib/","handlingStrategy":"validation","validationCode":"// Check required jars are present before init\ntry {\n  Class.forName(\"edu.stanford.nlp.ie.crf.CRFClassifier\");\n} catch (ClassNotFoundException e) {\n  throw new IllegalStateException(\"CoreNLP jar missing from classpath\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  model = CRFClassifier.getClassifier(is);\n} catch (ClassNotFoundException e) {\n  log.severe(\"Model references missing class: \" + e.getMessage());\n  throw new UnavailableException(\"Missing CoreNLP models jar\");\n}","preventionTips":["Ship the CoreNLP models jar matching your CoreNLP jar version in WEB-INF/lib.","Log the resolved CoreNLP version at startup and assert it matches models.","If using custom feature factories, include those classes in the WAR."],"tags":["classpath","deserialization","class-not-found","servlet"],"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-17T15:17:12.973Z"}