stanfordnlp/CoreNLP · error · IllegalStateException

Parser has not been loaded and initialized; first load a…

Error message

Parser has not been  loaded and initialized; first load a model.

What it means

DependencyParser.predict(CoreMap) requires the parser's internal transition `system` to be built, which happens during initialize() after loading a model. If system is null the model was never loaded/initialized, so IllegalStateException is thrown, telling the user to load a model first.

Solutions

  1. Load a model before predicting: DependencyParser.load(modelPath) or parser.loadModelFile(path)
  2. Ensure loadModel was followed by the initialization step (initialize()) if calling internal APIs
  3. If using a pipeline, add the dependency parser annotator so it loads its model during setup

Example fix

// before
DependencyParser parser = new DependencyParser(config);
parser.predict(sentence); // throws
// after
DependencyParser parser = DependencyParser.load("UD_English/model.txt.gz");
parser.predict(sentence);
Defensive patterns

Strategy: try-catch

Validate before calling

DependencyParser parser = DependencyParser.load(modelPath); // guarantees system is initialized
parser.predict(sentence);

Try / catch

try {
  parser.predict(sentence);
} catch (IllegalStateException e) {
  parser = DependencyParser.load(modelPath); // lazy (re)load then retry
  parser.predict(sentence);
}

Prevention

When it happens

Trigger: Calling predict(sentence) or predictAnnotation on a DependencyParser instance obtained via a bare constructor (or static helpers that returned before initialize) without calling loadModel()/loadFromModelFile first.

Common situations: Instantiating `new DependencyParser()` for inference instead of DependencyParser.load(modelPath); forgetting to call initialize after load when calling lower-level APIs; a failed/unsuccessful model load path that left the parser half-constructed.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/nndep/DependencyParser.java:977

            optTrans = tr;
          }
        }
      }
      system.apply(c, optTrans);
    }
    return c.tree;
  }

  /**
   * Determine the dependency parse of the given sentence using the loaded model.
   * You must first load a parser before calling this method.
   *
   * @throws java.lang.IllegalStateException If parser has not yet been loaded and initialized
   *         (see {@link #initialize(boolean)}
   */
  public GrammaticalStructure predict(CoreMap sentence) {
    if (system == null)
      throw new IllegalStateException("Parser has not been  " +
          "loaded and initialized; first load a model.");

    DependencyTree result = predictInner(sentence);

    // The rest of this method is just busy-work to convert the
    // package-local representation into a CoreNLP-standard
    // GrammaticalStructure.

    List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
    List<TypedDependency> dependencies = new ArrayList<>();

    IndexedWord root = new IndexedWord(new Word("ROOT"));
    root.set(CoreAnnotations.IndexAnnotation.class, 0);

    for (int i = 1; i <= result.n; i++) {
      int head = result.getHead(i);
      String label = result.getLabel(i);

View on GitHub (pinned to 1b7edd19c4)