stanfordnlp/CoreNLP · error · UnsupportedOperationException
You must use a tree type that implements scoring in order…
Error message
You must use a tree type that implements scoring in order call setScore()
What it means
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.
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
Example fix
// before TreeFactory tf = new TreeFactory(); // produces non-scoring nodes tree.setScore(1.0); // after TreeFactory tf = LabeledScoredTreeFactory.defaultTreeFactory(); tree.setScore(1.0); // supported
Defensive patterns
Strategy: validation
Validate before calling
if (!(tree.label() instanceof HasScore)) throw new IllegalStateException("tree labels do not support scoring; use a scoring tree factory"); Type guard
boolean isScoringTree(Tree t) { return t instanceof LabeledScoredTreeNode || t.label() instanceof HasScore; } Try / catch
try { tree.setScore(score); } catch (UnsupportedOperationException e) { tree = convertToScoredTree(tree); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Can only set spans on trees which use CoreLabel
- Can't set Tree labels
- Cannot set from string
- Cannot set from string
- Constituent can't be multilabeled
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/cbb0c0ecabae3496.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/Tree.java:403
/**
* Returns the score associated with the current node, or NaN
* if there is no score. The default implementation returns NaN.
*
* @return The score
*/
@Override
public double score() {
return Double.NaN;
}
/**
* Sets the score associated with the current node, if there is one.
*
* @param score The score
*/
public void setScore(double score) {
throw new UnsupportedOperationException("You must use a tree type that implements scoring in order call setScore()");
}
/**
* Returns the first child of a tree, or {@code null} if none.
*
* @return The first child
*/
public Tree firstChild() {
Tree[] kids = children();
if (kids.length == 0) {
return null;
}
return kids[0];
}
/**View on GitHub (pinned to 1b7edd19c4)