stanfordnlp/CoreNLP · critical · javax.servlet.ServletException

IO problem reading classifier.

Error message

IO problem reading classifier.

What it means

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.

Solutions

  1. Re-copy the model file and verify integrity (checksum or test: gunzip -t file.gz)
  2. Only use the .gz suffix for genuinely gzip-compressed models; rename or recompress accordingly
  3. Check disk space and container read permissions for WEB-INF/data/models
  4. Test loading the model outside the servlet with CRFClassifier.getClassifier(String path) to isolate the cause

Example fix

// before: plain serialized model named with .gz suffix -> GZIPInputStream throws
InputStream is = ctx.getResourceAsStream("/WEB-INF/data/models/model.ser.gz");
// after: rename to .ser (no gz) and ensure init-param filename matches
InputStream is = ctx.getResourceAsStream("/WEB-INF/data/models/model.ser");
Defensive patterns

Strategy: try-catch

Validate before calling

try (InputStream test = ctx.getResourceAsStream(modelPath)) {
  if (modelPath.endsWith(".gz")) new GZIPInputStream(test).read(); // fail fast on bad gzip
}

Try / catch

try { model = CRFClassifier.getClassifier(is); } catch (IOException e) { throw new ServletException("Corrupt/truncated model: " + modelPath, e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/545b08824a47ab44. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java:84

    ners = new HashMap<>();
    for (String classifier : classifiers) {
      CRFClassifier<CoreMap> model = null;
      String filename = "/WEB-INF/data/models/" + classifier;
      InputStream is = getServletConfig().getServletContext().getResourceAsStream(filename);

      if (is == null) {
        throw new ServletException("File not found. Filename = " + filename);
      }
      try {
        if (filename.endsWith(".gz")) {
          is = new BufferedInputStream(new GZIPInputStream(is));
        } else {
          is = new BufferedInputStream(is);
        }
        model = CRFClassifier.getClassifier(is);
      } catch (IOException e) {
        throw new ServletException("IO problem reading classifier.");
      } catch (ClassCastException e) {
        throw new ServletException("Classifier class casting problem.");
      } catch (ClassNotFoundException e) {
        throw new ServletException("Classifier class not found problem.");
      } finally {
        IOUtils.closeIgnoringExceptions(is);
      }
      ners.put(classifier, model);
    }
  }

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    if (request.getCharacterEncoding() == null) {
      request.setCharacterEncoding("utf-8");
    }

View on GitHub (pinned to 1b7edd19c4)