{"record":{"id":"cbb0c0ecabae3496","repo":"stanfordnlp/CoreNLP","slug":"you-must-use-a-tree-type-that-implements-scoring-i","errorCode":null,"errorMessage":"You must use a tree type that implements scoring in order call setScore()","messagePattern":"You must use a tree type that implements scoring in order call setScore\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/Tree.java","lineNumber":403,"sourceCode":"  /**\n   * Returns the score associated with the current node, or NaN\n   * if there is no score.  The default implementation returns NaN.\n   *\n   * @return The score\n   */\n  @Override\n  public double score() {\n    return Double.NaN;\n  }\n\n\n  /**\n   * Sets the score associated with the current node, if there is one.\n   *\n   * @param score The score\n   */\n  public void setScore(double score) {\n    throw new UnsupportedOperationException(\"You must use a tree type that implements scoring in order call setScore()\");\n  }\n\n\n  /**\n   * Returns the first child of a tree, or {@code null} if none.\n   *\n   * @return The first child\n   */\n  public Tree firstChild() {\n    Tree[] kids = children();\n    if (kids.length == 0) {\n      return null;\n    }\n    return kids[0];\n  }\n\n\n  /**","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/Tree.java#L385-L421","documentation":"Plain Tree nodes carry no score; scoring is implemented only by subclasses such as LabeledScoredTree whose labels support scores. The base Tree.setScore(double) throws UnsupportedOperationException because there is nowhere to store the score. The message tells you to use a tree type that implements scoring.","triggerScenarios":"Calling setScore(double) directly on a Tree object whose concrete class does not override setScore (e.g. LabeledTree without scoring labels, TreeGraphNode, or a plain Tree); also reached indirectly from transformTree/transformTreeHelper, scoreBinarizedTree, extractBestParse, parse, or nanScores operating on non-scoring tree types.","commonSituations":"Using a parser/transformer pipeline that expects scored trees (e.g. after binarization) but supplying trees built with a label factory that produces unscored labels; mixing tree factories so nodes lose their scoring behavior.","solutions":["Build trees with a scoring factory, e.g. use LabeledScoredTreeFactory (or a CoreLabel factory whose labels implement HasScore) so setScore is supported","Call scoreNodes()/ensure that tree labels implement HasScore before invoking score-dependent transforms","Check tree.getClass() / label type and route non-scoring trees away from code paths that call setScore"],"exampleFix":"// before\nTreeFactory tf = new TreeFactory(); // produces non-scoring nodes\ntree.setScore(1.0);\n// after\nTreeFactory tf = LabeledScoredTreeFactory.defaultTreeFactory();\ntree.setScore(1.0); // supported","handlingStrategy":"validation","validationCode":"if (!(tree.label() instanceof HasScore)) throw new IllegalStateException(\"tree labels do not support scoring; use a scoring tree factory\");","typeGuard":"boolean isScoringTree(Tree t) { return t instanceof LabeledScoredTreeNode || t.label() instanceof HasScore; }","tryCatchPattern":"try { tree.setScore(score); } catch (UnsupportedOperationException e) { tree = convertToScoredTree(tree); }","preventionTips":["Use LabeledScoredTreeFactory for trees destined for scoring pipelines","Ensure labels implement HasScore before calling setScore","Audit tree-producing code paths so all nodes come from the same scoring factory"],"tags":["unsupported-operation","nlp","scoring"],"backgroundTag":"unsupported-operation","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"}