stanfordnlp/CoreNLP · error

Could not pre-load annotators in server; encountered excepti

Error message

Could not pre-load annotators in server; encountered exception:

What it means

At server startup, StanfordCoreNLPServer optionally constructs a StanfordCoreNLP pipeline to pre-load the annotators listed by -preloadedAnnotators (or the server default properties) so the first request is fast. If that construction throws any Throwable, the server logs this message plus the throwable and continues starting WITHOUT pre-loaded annotators, so the first real request will pay the model-loading cost or fail.

Solutions

  1. Read the subsequent logged throwable to identify the root cause (missing model, unknown annotator, OOM).
  2. Correct the -preloadedAnnotators list: valid names, in dependency order (e.g. tokenize,ssplit,pos,lemma,ner).
  3. Ensure the models jar is on the classpath so every preloaded annotator's model files resolve.
  4. Increase heap (-mx8g) if the throwable is OutOfMemoryError; preload fewer annotators otherwise.

Example fix

// before
java -mx4g -cp corenlp.jar:models.jar StanfordCoreNLPServer -preloadedAnnotators tokenize,ssplit,pos,ner
// after (ner needs tokenize,ssplit,pos anyway; fix typo / ordering)
java -mx8g -cp corenlp.jar:models.jar StanfordCoreNLPServer -preloadedAnnotators tokenize,ssplit,pos,lemma,ner
Defensive patterns

Strategy: validation

Validate before calling

Set<String> valid = Set.of("tokenize","ssplit","pos","lemma","ner","parse","depparse","sentiment","coref");
for (String a : preloadList.split(",")) {
    if (!valid.contains(a.trim())) throw new IllegalArgumentException("Unknown annotator: " + a);
}
if (Runtime.getRuntime().maxMemory() < 4L*1024*1024*1024) warn("Low heap for preloading");

Prevention

When it happens

Trigger: Starting the server with -preloadedAnnotators naming annotators whose models are missing/corrupt, an invalid annotator name in server.defaultProps' annotators key, or any exception (including OOM) during pipeline construction in the constructor's preload block.

Common situations: Typo in the annotators list (e.g. 'depparsee'); models jar not on classpath; specifying an annotator requiring another annotator (e.g. ner without tokenize/ssplit/pos); insufficient -mx heap causing OutOfMemoryError during preload.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java:1882

      homepage = new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-brat.html");
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }

    // Pre-load the models
    if (StanfordCoreNLPServer.preloadedAnnotators != null) {
      Properties props = new Properties();
      server.defaultProps.forEach((key1, value) -> props.setProperty(key1.toString(), value.toString()));
      // -preload flag alone means to load all default annotators
      // -preload flag with a list of annotators means to preload just that list (e.g. tokenize,ssplit,pos)
      String annotatorsToLoad = (StanfordCoreNLPServer.preloadedAnnotators.trim().equals("true")) ?
          server.defaultProps.getProperty("annotators") : StanfordCoreNLPServer.preloadedAnnotators;
      if (annotatorsToLoad != null)
        props.setProperty("annotators", annotatorsToLoad);
      try {
        new StanfordCoreNLP(props);
      } catch (Throwable throwable) {
        err("Could not pre-load annotators in server; encountered exception:");
        err(throwable);
      }
    }

    // Credentials
    Optional<Pair<String, String>> credentials = Optional.empty();
    if (server.username != null && server.password != null) {
      credentials = Optional.of(Pair.makePair(server.username, server.password));
    }

    // Run the server
    log("Starting server...");
    server.run(credentials, req -> true, res -> {}, homepage, server.ssl, live);

    return server;
  } // end launchServer

View on GitHub (pinned to 1b7edd19c4)