stanfordnlp/CoreNLP · error · IllegalArgumentException

This evaluator only works for the ShiftReduceParser

Error message

This evaluator only works for the ShiftReduceParser

What it means

TreeRecorder is a ParserQueryEval that records trees (e.g. binarized or debinarized gold/system outputs) from parse queries. Like the other shift-reduce evaluators, it requires a ShiftReduceParserQuery to obtain the transition sequence/tree; any other ParserQuery type triggers this IllegalArgumentException.

Solutions

  1. Only attach TreeRecorder to ShiftReduceParser evaluation runs
  2. Filter the evaluator list by parser type before running evaluation
  3. If you need equivalent recording for other parsers, implement a dedicated evaluator for that parser's query type

Example fix

// before
for (ParserQueryEval eval : evals) { eval.evaluate(parserQuery, gold, pw); }

// after
for (ParserQueryEval eval : evals) {
  if (eval instanceof TreeRecorder && !(parserQuery instanceof ShiftReduceParserQuery)) continue;
  eval.evaluate(parserQuery, gold, pw);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(query instanceof ShiftReduceParserQuery)) {
  log.warning("TreeRecorder requires ShiftReduceParserQuery; skipping");
  return;
}

Type guard

boolean canRecordTree(ParserQuery q) {
  return q instanceof ShiftReduceParserQuery;
}

Try / catch

try {
  recorder.evaluate(query, gold, pw);
} catch (IllegalArgumentException e) {
  log.warning("TreeRecorder skipped: " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling TreeRecorder.evaluate (public ParserQueryEval entry point) with a ParserQuery produced by a non-shift-reduce parser, i.e. not instanceof ShiftReduceParserQuery.

Common situations: Recording tree outputs during evaluation runs of a different parser; a generic evaluation harness that applies all registered evaluators regardless of parser type.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java:39

    BINARIZED, DEBINARIZED
  };

  private final Mode mode;

  private final BufferedWriter out;

  public TreeRecorder(Mode mode, String filename) {
    this.mode = mode;
    try {
      out = new BufferedWriter(new FileWriter(filename));
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
  }

  public void evaluate(ParserQuery query, Tree gold, PrintWriter pw) {
    if (!(query instanceof ShiftReduceParserQuery)) {
      throw new IllegalArgumentException("This evaluator only works for the ShiftReduceParser");
    }
    
    ShiftReduceParserQuery srquery = (ShiftReduceParserQuery) query;
    try {
      switch (mode) {
      case BINARIZED:
        out.write(srquery.getBestBinarizedParse().toString());
        break;
      case DEBINARIZED:
        out.write(srquery.debinarized.toString());
        break;
      default:
        throw new IllegalArgumentException("Unknown mode " + mode);
      }
      out.newLine();
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }

View on GitHub (pinned to 1b7edd19c4)