{"record":{"id":"5feceecf3f2d0cbc","repo":"stanfordnlp/CoreNLP","slug":"unexpected-node-class","errorCode":null,"errorMessage":"Unexpected node class","messagePattern":"Unexpected node class","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/fsm/TransducerGraph.java","lineNumber":477,"sourceCode":"\n  public static class SetToStringNodeProcessor implements NodeProcessor {\n    private TreebankLanguagePack tlp;\n\n    public SetToStringNodeProcessor(TreebankLanguagePack tlp) {\n      this.tlp = tlp;\n    }\n\n    @Override\n    public Object processNode(Object node) {\n      Set s = null;\n      if (node instanceof Set) {\n        s = (Set) node;\n      } else {\n        if (node instanceof Block) {\n          Block b = (Block) node;\n          s = b.getMembers();\n        } else {\n          throw new RuntimeException(\"Unexpected node class\");\n        }\n      }\n      Object sampleNode = s.iterator().next();\n      if (s.size() == 1) {\n        if (sampleNode instanceof Block) {\n          return processNode(sampleNode);\n        } else {\n          return sampleNode;\n        }\n      }\n      // nope there's a set of things\n      if (sampleNode instanceof String) {\n        String str = (String) sampleNode;\n        if (str.charAt(0) != '@') {\n          // passive category...\n          return tlp.basicCategory(str) + \"-\" + s.hashCode(); // TODO remove b/c there could be collisions\n          //          return tlp.basicCategory(str) + \"-\" + System.identityHashCode(s);\n        }","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/fsm/TransducerGraph.java#L459-L495","documentation":"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.","triggerScenarios":"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).","commonSituations":"Extending TransducerGraph with custom node types; loading graphs built by other code that used nonstandard node objects; refactoring that changed node representation.","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"],"exampleFix":"// before\nObject node = new MyNode(\"x\");\ngraph.addArc(node, target, input);\n// after\nObject node = \"x\"; // use a supported node type\ngraph.addArc(node, target, input);","handlingStrategy":"type-guard","validationCode":"// Only add supported node types to the graph\nif (!(node instanceof String || node instanceof java.util.Set || node instanceof TransducerGraph.Block))\n  throw new IllegalArgumentException(\"Unsupported node class: \" + node.getClass());","typeGuard":"boolean isSupportedNode(Object n) {\n  return n instanceof String || n instanceof java.util.Set || n instanceof TransducerGraph.Block;\n}","tryCatchPattern":"try {\n  String s = graph.processNode(node);\n} catch (RuntimeException e) {\n  if (\"Unexpected node class\".equals(e.getMessage())) {\n    String s = String.valueOf(node); // fallback rendering\n  } else throw e;\n}","preventionTips":["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"],"tags":["java","fsm","graph","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}