stanfordnlp/CoreNLP · error · RuntimeException

Coordination node must have at least 2 children.

Error message

Coordination node must have at least 2 children.

What it means

A tregex CoordinationPattern represents an AND/OR node over child patterns; a coordination with fewer than two children is meaningless, so the constructor throws RuntimeException. This is an internal invariant enforced when building patterns from parsed tregex expressions.

Solutions

  1. Ensure the children list has at least 2 TregexPattern objects before constructing the node
  2. If only one child remains, use the child pattern directly instead of wrapping it in a coordination
  3. If no children remain, return a trivially-true pattern or skip constructing the node
  4. Check pattern-parsing/filtering logic for clauses being dropped incorrectly

Example fix

// before
return new CoordinationPattern(children, true); // children.size() == 1
// after
if (children.size() == 1) return children.get(0);
return new CoordinationPattern(children, true);
Defensive patterns

Strategy: validation

Validate before calling

if (children == null || children.size() < 2)
  throw new IllegalArgumentException("CoordinationPattern needs >= 2 children, got " + (children == null ? 0 : children.size()));

Try / catch

try {
  pattern = new CoordinationPattern(children, true);
} catch (RuntimeException e) {
  pattern = children.isEmpty() ? null : children.get(0); // degenerate case
}

Prevention

When it happens

Trigger: Constructing new CoordinationPattern(list, conj) with a list of size 0 or 1, e.g. when programmatically building tregex patterns or when a parser bug yields a degenerate conjunction/disjunction.

Common situations: Custom code that composes TregexPattern objects programmatically; deserializing or rebuilding patterns from stored tregex strings with only one clause after filtering.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/tregex/CoordinationPattern.java:20

import edu.stanford.nlp.trees.HeadFinder;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.VariableStrings;

import java.util.Iterator;
import java.util.List;
import java.util.IdentityHashMap;
import java.util.Map;

class CoordinationPattern extends TregexPattern {

  private final boolean isConj;
  private final List<TregexPattern> children;

  /* if isConj is true, then it is an "AND" ; if it is false, it is an "OR".*/
  public CoordinationPattern(List<TregexPattern> children, boolean isConj) {
    if (children.size() < 2) {
      throw new RuntimeException("Coordination node must have at least 2 children.");
    }
    this.children = children;
    this.isConj = isConj;
    //    System.out.println("Made " + (isConj ? "and " : "or ") + "node with " + children.size() + " children.");
  }

  @Override
  public List<TregexPattern> getChildren() {
    return children;
  }

  @Override
  public String localString() {
    return (isConj ? "and" : "or");
  }

  @Override
  public String toString() {

View on GitHub (pinned to 1b7edd19c4)