{"record":{"id":"3eec19cc10d56fe3","repo":"stanfordnlp/CoreNLP","slug":"governor-or-dependent-cannot-be-null","errorCode":null,"errorMessage":"governor or dependent cannot be null","messagePattern":"governor or dependent cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/UnnamedDependency.java","lineNumber":38,"sourceCode":"\n  private static final long serialVersionUID = -3768440215342256085L;\n\n  // We store the text of the labels separately because it looks like\n  // it is possible for an object to request a hash code using itself\n  // in a partially reconstructed state when unserializing.  For\n  // example, a TreeGraphNode might ask for the hash code of an\n  // UnnamedDependency, which then uses an unfilled member of the same\n  // TreeGraphNode to get the hash code.  Keeping the text of the\n  // labels breaks that possible cycle.\n  protected final String regentText;\n  protected final String dependentText;\n\n  private final Label regent;\n  private final Label dependent;\n\n  public UnnamedDependency(String regent, String dependent) {\n    if (regent == null || dependent == null) {\n      throw new IllegalArgumentException(\"governor or dependent cannot be null\");\n    }\n    \n    CoreLabel headLabel = new CoreLabel();\n    headLabel.setValue(regent);\n    headLabel.setWord(regent);\n    this.regent = headLabel;\n    \n    CoreLabel depLabel = new CoreLabel();\n    depLabel.setValue(dependent);\n    depLabel.setWord(dependent);\n    this.dependent = depLabel;\n\n    regentText = regent;\n    dependentText = dependent;\n  }\n\n  public UnnamedDependency(Label regent, Label dependent) {\n    if (regent == null || dependent == null) {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/UnnamedDependency.java#L20-L56","documentation":"The UnnamedDependency(String, String) constructor rejects null regent or dependent words, since a dependency edge must reference two actual tokens. Either argument null triggers IllegalArgumentException at construction time.","triggerScenarios":"new UnnamedDependency(null, dependentString) or new UnnamedDependency(regentString, null), typically when regent/dependent come from nullable lookups (parser output, map lookups, optional tokens).","commonSituations":"Building dependency edges from data with missing head or child tokens (e.g. ROOT pseudo-tokens not handled, empty extractions from relation extraction or dependency conversion).","solutions":["Check both strings for null before constructing and skip or log the edge","Substitute a placeholder like \"ROOT\" when a null head is semantically valid","Fix the upstream extraction so missing tokens are filtered out earlier"],"exampleFix":"// before\nedges.add(new UnnamedDependency(headStr, depStr));\n// after\nif (headStr != null && depStr != null) {\n  edges.add(new UnnamedDependency(headStr, depStr));\n}","handlingStrategy":"validation","validationCode":"if (regent == null || dependent == null) {\n  throw new IllegalArgumentException(\"cannot build dependency from null token\");\n}\nnew UnnamedDependency(regent, dependent);","typeGuard":"boolean isBuildable(String regent, String dependent) {\n  return regent != null && dependent != null && !regent.isEmpty() && !dependent.isEmpty();\n}","tryCatchPattern":"try {\n  edges.add(new UnnamedDependency(regentStr, dependentStr));\n} catch (IllegalArgumentException e) {\n  logger.debug(\"skipping null-token edge\");\n}","preventionTips":["Filter null tokens at extraction time","Use placeholders for ROOT heads when needed","Assert non-null tokens in pipeline output tests"],"tags":["java","dependencies","null-check"],"backgroundTag":"null-argument","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"}