stanfordnlp/CoreNLP · error · UnsupportedOperationException
Constituent can't be multilabeled
Error message
Constituent can't be multilabeled
What it means
The base Constituent class supports only a single label (label()/setLabel()); its setLabels(Collection) contract from Labeled exists for subclasses that allow multiple labels. The default implementation throws UnsupportedOperationException because a plain Constituent cannot be multilabeled.
Solutions
- Use setLabel(Label) (singular) instead of setLabels(Collection) on plain constituents.
- Use a multilabeled constituent subclass that overrides setLabels if multiple labels are truly needed.
- Check the runtime type before calling setLabels and route accordingly.
Example fix
// before constituent.setLabels(Collections.singletonList(label)); // after constituent.setLabel(label);
Defensive patterns
Strategy: type-guard
Validate before calling
if (c.labels().size() > 1 || needMultipleLabels) { useMultilabeledConstituent(c); } Type guard
boolean supportsMultiLabel(Labeled l) { try { l.setLabels(l.labels()); return true; } catch (UnsupportedOperationException e) { return false; } } Try / catch
try { c.setLabels(newLabels); } catch (UnsupportedOperationException e) { c.setLabel(newLabels.iterator().next()); } Prevention
- Use setLabel (singular) on base Constituents
- Only call setLabels on subclasses documented as multilabeled
When it happens
Trigger: Calling setLabels(...) on any Constituent instance that is not a multilabeled subclass (e.g. on a LabeledConstituent used via the base Constituent API or on a simple Constituent).
Common situations: Generic code that re-labels Labeled objects (e.g. tree normalization or filter pipelines) hitting a Constituent; copying labels between constituents assuming Labeled semantics.
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
- Cannot set from string
- Cannot set from string
- Dependencies type not implemented
- : Does not support parse operation.
- Doesn't do best parses yet
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/509fb6950db00bab.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/Constituent.java:78
/**
* Sets the label associated with the current Constituent,
* if there is one.
*/
public void setLabel(Label label) {
// a noop
}
/**
* Access labels -- actually always a singleton here.
*/
public Collection<Label> labels() {
return Collections.singletonList(label());
}
public void setLabels(Collection<Label> labels) {
throw new UnsupportedOperationException("Constituent can't be multilabeled");
}
/**
* access score
*/
public double score() {
return Double.NaN;
}
/**
* Sets the score associated with the current node, if there is one
*/
public void setScore(double score) {
// a no-op
}
View on GitHub (pinned to 1b7edd19c4)