stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown side

Error message

Unknown side <side>

What it means

BinaryTransition.apply() switches on the transition's Side enum (LEFT/RIGHT) when choosing which stack node is the head; an unrecognized side value falls to the default and throws IllegalArgumentException. With only two enum constants this normally indicates a corrupted or externally constructed transition.

Solutions

  1. Ensure BinaryTransition is always created via its constructor with Side.LEFT or Side.RIGHT.
  2. Check that transition sequences were serialized/deserialized with matching CoreNLP versions.
  3. Add an assertion/log of transition.side before calling apply() in custom training loops.
  4. Rebuild the transition sequence from the tree rather than reusing stale transition objects.

Example fix

// before
new BinaryTransition(label, null, isRoot);
// after
new BinaryTransition(label, BinaryTransition.Side.LEFT, isRoot);
Defensive patterns

Strategy: type-guard

Validate before calling

if (t instanceof BinaryTransition && t.side != BinaryTransition.Side.LEFT && t.side != BinaryTransition.Side.RIGHT)
    throw new IllegalStateException("Invalid BinaryTransition side");

Type guard

boolean hasValidSide(BinaryTransition t) {
    return t.side == BinaryTransition.Side.LEFT || t.side == BinaryTransition.Side.RIGHT;
}

Try / catch

try {
    transition.apply(state);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unknown side")) {
        // discard/rebuild the transition sequence
    }
}

Prevention

When it happens

Trigger: Applying a BinaryTransition whose side field is null or a deserialized/modified value outside {LEFT, RIGHT}, e.g. from hand-built transition sequences or bad serialization.

Common situations: Custom training code constructing BinaryTransition with a side not set, Java deserialization of an altered enum, or third-party code injecting invalid states into the shift-reduce parser.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/shiftreduce/BinaryTransition.java:199

   * Add a binary node to the existing node on top of the stack
   */
  public State apply(State state, double scoreDelta) {
    TreeShapedStack<Tree> stack = state.stack;
    Tree right = stack.peek();
    stack = stack.pop();
    Tree left = stack.peek();
    stack = stack.pop();

    Tree head;
    switch(side) {
    case LEFT:
      head = left;
      break;
    case RIGHT:
      head = right;
      break;
    default:
      throw new IllegalArgumentException("Unknown side " + side);
    }

    if (!(head.label() instanceof CoreLabel)) {
      throw new IllegalArgumentException("Stack should have CoreLabel nodes");
    }
    CoreLabel headLabel = (CoreLabel) head.label();

    CoreLabel production = new CoreLabel();
    production.setValue(label);
    production.set(TreeCoreAnnotations.HeadWordLabelAnnotation.class, headLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class));
    production.set(TreeCoreAnnotations.HeadTagLabelAnnotation.class, headLabel.get(TreeCoreAnnotations.HeadTagLabelAnnotation.class));
    Tree newTop = new LabeledScoredTreeNode(production);
    newTop.addChild(left);
    newTop.addChild(right);

    stack = stack.push(newTop);

    return new State(stack, state.transitions.push(this), state.separators, state.sentence, state.tokenPosition, state.score + scoreDelta, false);

View on GitHub (pinned to 1b7edd19c4)