stanfordnlp/CoreNLP · error · RuntimeException

Mismatch between number of morpho analyses and number of…

Error message

Mismatch between number of morpho analyses and number of input lines.

What it means

AddMorphoAnnotations main loop reads trees one per line and consumes morphological analyses from a parallel iterator; it throws this RuntimeException when trees remain but the morpho iterator is exhausted, i.e. there are more input trees than morpho analyses.

Solutions

  1. Recount lines in both input files and ensure the morpho file has one entry per tree line
  2. Regenerate the morpho analyses file against the same tree input
  3. Skip/check for blank lines that desynchronize the two files
  4. Exit early with a clear message if counts differ before processing

Example fix

// before
wc -l trees.txt  # 1000
wc -l morpho.txt # 998
// after
wc -l morpho.txt # 1000 (regenerate to match)
Defensive patterns

Strategy: validation

Validate before calling

if (nTreeLines != nMorphoLines) throw new IllegalStateException("trees=" + nTreeLines + " morpho=" + nMorphoLines);

Try / catch

try { process(); } catch (RuntimeException e) { log.error("Input length mismatch: " + e.getMessage()); System.exit(2); }

Prevention

When it happens

Trigger: Running AddMorphoAnnotations where the morpho analyses file has fewer entries than the tree file has lines; loop iteration reaches a tree with !morphIter.hasNext().

Common situations: Truncated morpho file, mismatched line counts between tree and morpho inputs, blank lines filtered from one file but not the other.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/morph/AddMorphoAnnotations.java:172

      log.info(usage());
      System.exit(-1);
    }
    
    YieldIterator morphIter = new YieldIterator(parsedArgs[0], isMorphTreeFile);
    YieldIterator lemmaIter = new YieldIterator(parsedArgs[1], false);
    
    final Pattern pParenStripper = Pattern.compile("[\\(\\)]");
        
    try {
      BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in, encoding));
      TreeReaderFactory trf = new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory(true);

      int nTrees = 0;
      for(String line; (line = brIn.readLine()) != null; ++nTrees) {
        Tree tree = trf.newTreeReader(new StringReader(line)).readTree();
        List<Tree> leaves = tree.getLeaves();
        if(!morphIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of morpho analyses and number of input lines.");
        }
        List<String> morphTags = morphIter.next();
        if (!lemmaIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of lemmas and number of input lines.");
        }
        List<String> lemmas = lemmaIter.next();
         
        // Sanity checks
        assert morphTags.size() == lemmas.size();
        assert lemmas.size() == leaves.size();
        
        for(int i = 0; i < leaves.size(); ++i) {
          String morphTag = morphTags.get(i);
          if (pParenStripper.matcher(morphTag).find()) {
            morphTag = pParenStripper.matcher(morphTag).replaceAll("");
          }
          String newLeaf = String.format("%s%s%s%s%s", leaves.get(i).value(),
              MorphoFeatureSpecification.MORPHO_MARK,

View on GitHub (pinned to 1b7edd19c4)