{"record":{"id":"06fa71f9482ebbf8","repo":"stanfordnlp/CoreNLP","slug":"this-evaluator-only-works-for-the-shiftreduceparse-06fa71","errorCode":null,"errorMessage":"This evaluator only works for the ShiftReduceParser","messagePattern":"This evaluator only works for the ShiftReduceParser","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java","lineNumber":39,"sourceCode":"    BINARIZED, DEBINARIZED\n  };\n\n  private final Mode mode;\n\n  private final BufferedWriter out;\n\n  public TreeRecorder(Mode mode, String filename) {\n    this.mode = mode;\n    try {\n      out = new BufferedWriter(new FileWriter(filename));\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n  public void evaluate(ParserQuery query, Tree gold, PrintWriter pw) {\n    if (!(query instanceof ShiftReduceParserQuery)) {\n      throw new IllegalArgumentException(\"This evaluator only works for the ShiftReduceParser\");\n    }\n    \n    ShiftReduceParserQuery srquery = (ShiftReduceParserQuery) query;\n    try {\n      switch (mode) {\n      case BINARIZED:\n        out.write(srquery.getBestBinarizedParse().toString());\n        break;\n      case DEBINARIZED:\n        out.write(srquery.debinarized.toString());\n        break;\n      default:\n        throw new IllegalArgumentException(\"Unknown mode \" + mode);\n      }\n      out.newLine();\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java#L21-L57","documentation":"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.","triggerScenarios":"Calling TreeRecorder.evaluate (public ParserQueryEval entry point) with a ParserQuery produced by a non-shift-reduce parser, i.e. not instanceof ShiftReduceParserQuery.","commonSituations":"Recording tree outputs during evaluation runs of a different parser; a generic evaluation harness that applies all registered evaluators regardless of parser type.","solutions":["Only attach TreeRecorder to ShiftReduceParser evaluation runs","Filter the evaluator list by parser type before running evaluation","If you need equivalent recording for other parsers, implement a dedicated evaluator for that parser's query type"],"exampleFix":"// before\nfor (ParserQueryEval eval : evals) { eval.evaluate(parserQuery, gold, pw); }\n\n// after\nfor (ParserQueryEval eval : evals) {\n  if (eval instanceof TreeRecorder && !(parserQuery instanceof ShiftReduceParserQuery)) continue;\n  eval.evaluate(parserQuery, gold, pw);\n}","handlingStrategy":"type-guard","validationCode":"if (!(query instanceof ShiftReduceParserQuery)) {\n  log.warning(\"TreeRecorder requires ShiftReduceParserQuery; skipping\");\n  return;\n}","typeGuard":"boolean canRecordTree(ParserQuery q) {\n  return q instanceof ShiftReduceParserQuery;\n}","tryCatchPattern":"try {\n  recorder.evaluate(query, gold, pw);\n} catch (IllegalArgumentException e) {\n  log.warning(\"TreeRecorder skipped: \" + e.getMessage());\n}","preventionTips":["Attach TreeRecorder only in shift-reduce evaluation configs","Guard generic evaluation loops with instanceof checks","Keep per-parser evaluator registries instead of one global list"],"tags":["parser","evaluation","type-mismatch","api-usage"],"backgroundTag":"incompatible-source-type","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}