{"record":{"id":"abc204fb1dde97d4","repo":"stanfordnlp/CoreNLP","slug":"file-not-found-filename-filename","errorCode":null,"errorMessage":"File not found. Filename = \" + filename","messagePattern":"File not found\\. Filename = \" \\+ filename","errorType":"http","errorClass":"javax.servlet.ServletException","httpStatus":500,"severity":"critical","filePath":"src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java","lineNumber":74,"sourceCode":"    String path = getServletContext().getRealPath(\"/WEB-INF/data/models\");\n    for (String classifier : new File(path).list()) {\n      classifiers.add(classifier);\n    }\n    // TODO: get this from somewhere more interesting?\n    defaultClassifier = classifiers.get(0);\n\n    for (String classifier : classifiers) {\n      log(classifier);\n    }\n\n    ners = new HashMap<>();\n    for (String classifier : classifiers) {\n      CRFClassifier<CoreMap> model = null;\n      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);","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java#L56-L92","documentation":"During init(), NERServlet loads each configured classifier model via ServletContext.getResourceAsStream. If the stream is null — the resource '/WEB-INF/data/models/<classifier>' does not exist in the webapp — it throws ServletException naming the missing filename.","triggerScenarios":"init-param listing classifier model files that were never placed under the webapp's WEB-INF/data/models directory; misspelled model filenames; WAR packaging that excludes .ser/.gz model files.","commonSituations":"Building the WAR without the large model files (excluded by build config or .gitignore); renaming models on disk but not in the classifier init-param; deploying a slimmed distribution.","solutions":["Copy the required classifier model files into src/main/webapp/WEB-INF/data/models/ and rebuild the WAR","Match the classifier init-param names exactly to the filenames present in WEB-INF/data/models","Check the build (Maven/Gradle) isn't filtering/excluding model resources from the WAR","Verify inside the deployed webapp container (not just the source tree) that the resource resolves"],"exampleFix":"<!-- before -->\n<init-param><param-name>classifiers</param-name><param-value>english.all.3class.distsim.crf.ser.gz</param-value></init-param>\n<!-- after: also ensure the file exists -->\n# cp english.all.3class.distsim.crf.ser.gz webapp/WEB-INF/data/models/\n<init-param><param-name>classifiers</param-name><param-value>english.all.3class.distsim.crf.ser.gz</param-value></init-param>","handlingStrategy":"try-catch","validationCode":"for (String c : classifierNames) {\n  if (getServletContext().getResourceAsStream(\"/WEB-INF/data/models/\" + c) == null)\n    throw new IllegalStateException(\"Model missing from WAR: \" + c);\n}","typeGuard":null,"tryCatchPattern":"try { servlet.init(cfg); } catch (ServletException e) { if (e.getMessage().startsWith(\"File not found\")) redeployWithModels(); }","preventionTips":["Bundle model files inside WEB-INF/data/models in the build","Verify WAR contents (jar tf app.war | grep models) before deploy","Keep init-param filenames in sync with packaged resources"],"tags":["java","servlet","file-not-found","deployment"],"backgroundTag":"resource-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"}