stanfordnlp/CoreNLP · error · RuntimeException
Unexpected node class
Error message
Unexpected node class
What it means
TransducerGraph.processNode converts graph node objects into their string form, supporting Strings, Sets, and Block instances; any other node class triggers this RuntimeException. It is an internal type expectation violation in graph output/processing.
Solutions
- Use String, Set, or TransducerGraph.Block as node objects
- Convert custom node objects to Strings before adding them to the graph
- Override/extend processNode in a subclass to handle your node class
- Inspect node creation code to find where the unsupported class was introduced
Example fix
// before
Object node = new MyNode("x");
graph.addArc(node, target, input);
// after
Object node = "x"; // use a supported node type
graph.addArc(node, target, input); Defensive patterns
Strategy: type-guard
Validate before calling
// Only add supported node types to the graph
if (!(node instanceof String || node instanceof java.util.Set || node instanceof TransducerGraph.Block))
throw new IllegalArgumentException("Unsupported node class: " + node.getClass()); Type guard
boolean isSupportedNode(Object n) {
return n instanceof String || n instanceof java.util.Set || n instanceof TransducerGraph.Block;
} Try / catch
try {
String s = graph.processNode(node);
} catch (RuntimeException e) {
if ("Unexpected node class".equals(e.getMessage())) {
String s = String.valueOf(node); // fallback rendering
} else throw e;
} Prevention
- Use String nodes unless you specifically need Set/Block grouping
- Normalize custom node objects to Strings at insertion time
- Subclass and override processNode if custom node payloads are required
- Document the node-type contract wherever graphs are built
When it happens
Trigger: Rendering/processing a TransducerGraph whose nodes were created with a custom object class rather than String, Set, or Block (e.g. user-defined node payloads passed to addArc or graph construction).
Common situations: Extending TransducerGraph with custom node types; loading graphs built by other code that used nonstandard node objects; refactoring that changed node representation.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Creating nondeterminism while inserting arc
- addFeature was called with a features object that is…
- Unknown value for span
- Attempting to remove features based on weight from a…
- String match result must be referred to by group id
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/5feceecf3f2d0cbc.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/fsm/TransducerGraph.java:477
public static class SetToStringNodeProcessor implements NodeProcessor {
private TreebankLanguagePack tlp;
public SetToStringNodeProcessor(TreebankLanguagePack tlp) {
this.tlp = tlp;
}
@Override
public Object processNode(Object node) {
Set s = null;
if (node instanceof Set) {
s = (Set) node;
} else {
if (node instanceof Block) {
Block b = (Block) node;
s = b.getMembers();
} else {
throw new RuntimeException("Unexpected node class");
}
}
Object sampleNode = s.iterator().next();
if (s.size() == 1) {
if (sampleNode instanceof Block) {
return processNode(sampleNode);
} else {
return sampleNode;
}
}
// nope there's a set of things
if (sampleNode instanceof String) {
String str = (String) sampleNode;
if (str.charAt(0) != '@') {
// passive category...
return tlp.basicCategory(str) + "-" + s.hashCode(); // TODO remove b/c there could be collisions
// return tlp.basicCategory(str) + "-" + System.identityHashCode(s);
}View on GitHub (pinned to 1b7edd19c4)