{"record":{"id":"545b08824a47ab44","repo":"stanfordnlp/CoreNLP","slug":"io-problem-reading-classifier","errorCode":null,"errorMessage":"IO problem reading classifier.","messagePattern":"IO problem reading classifier\\.","errorType":"http","errorClass":"javax.servlet.ServletException","httpStatus":500,"severity":"critical","filePath":"src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java","lineNumber":84,"sourceCode":"\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);\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    }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java#L66-L102","documentation":"While loading a classifier model in init(), an IOException from CRFClassifier.getClassifier(InputStream) (or the GZIP stream wrapper) is converted to ServletException 'IO problem reading classifier.' — the resource exists but its bytes could not be read/decoded.","triggerScenarios":"Model file truncated or corrupted (partial upload/copy); a .gz-named file that is not valid gzip (GZIPInputStream constructor throws IOException); storage/permission failure while the servlet reads the resource stream.","commonSituations":"Interrupted deployment or rsync leaving a partial model; renaming a plain .ser file to .ser.gz so it is gunzipped though never compressed; disk full or read-only mount under the container.","solutions":["Re-copy the model file and verify integrity (checksum or test: gunzip -t file.gz)","Only use the .gz suffix for genuinely gzip-compressed models; rename or recompress accordingly","Check disk space and container read permissions for WEB-INF/data/models","Test loading the model outside the servlet with CRFClassifier.getClassifier(String path) to isolate the cause"],"exampleFix":"// before: plain serialized model named with .gz suffix -> GZIPInputStream throws\nInputStream is = ctx.getResourceAsStream(\"/WEB-INF/data/models/model.ser.gz\");\n// after: rename to .ser (no gz) and ensure init-param filename matches\nInputStream is = ctx.getResourceAsStream(\"/WEB-INF/data/models/model.ser\");","handlingStrategy":"try-catch","validationCode":"try (InputStream test = ctx.getResourceAsStream(modelPath)) {\n  if (modelPath.endsWith(\".gz\")) new GZIPInputStream(test).read(); // fail fast on bad gzip\n}","typeGuard":null,"tryCatchPattern":"try { model = CRFClassifier.getClassifier(is); } catch (IOException e) { throw new ServletException(\"Corrupt/truncated model: \" + modelPath, e); }","preventionTips":["Verify model checksums after transfer","Only name files .gz if they are gzip-compressed","Preload models in a startup health check to catch corruption early"],"tags":["java","servlet","io","model-loading"],"backgroundTag":"file-read-failed","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"}