{"record":{"id":"30b4088234ba1793","repo":"stanfordnlp/CoreNLP","slug":"no-relation-given-for-an-adddep","errorCode":null,"errorMessage":"No relation given for an AddDep","messagePattern":"No relation given for an AddDep","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java","lineNumber":46,"sourceCode":"  final String govNodeName;\n  final String position;\n  final double weight;\n\n  public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, String> attributes, String position) {\n    this(govNodeName, relation, attributes, position, 0.0);\n  }\n\n  public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, String> attributes, String position, double weight) {\n    if (position != null) {\n      if (!position.startsWith(\"-\") && !position.startsWith(\"+\")) {\n        throw new SsurgeonParseException(\"Unknown position \" + position + \" in AddDep operation\");\n      }\n    }\n    if (govNodeName == null) {\n      throw new SsurgeonParseException(\"No governor given for an AddDep\");\n    }\n    if (relation == null) {\n      throw new SsurgeonParseException(\"No relation given for an AddDep\");\n    }\n    checkIllegalAttributes(attributes);\n\n    this.attributes = new TreeMap<>(attributes);\n    this.relation = relation;\n    this.govNodeName = govNodeName;\n    this.position = position;\n    this.weight = weight;\n  }\n\n  /**\n   * Emits a parseable instruction string.\n   */\n  @Override\n  public String toEditString() {\n    StringWriter buf = new StringWriter();\n    buf.write(LABEL);  buf.write(\"\\t\");\n    buf.write(Ssurgeon.GOV_NODENAME_ARG);buf.write(\" \");","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java#L28-L64","documentation":"AddDep requires a GrammaticalRelation for the new dependency edge; a null relation cannot produce a valid SemanticGraphEdge, so the constructor throws this SsurgeonParseException after the governor check.","triggerScenarios":"Calling new AddDep(govNodeName, null, attributes, position[, weight]); also occurs when Ssurgeon rule parsing builds an AddDep element with a missing or unrecognized relation attribute that resolves to null.","commonSituations":"Rule files missing the relation attribute; a relation string that failed to map to a GrammaticalRelation (e.g. not resolvable via UniversalSemanticGraphConverter/EnglishGrammaticalRelations); programmatic rule generation leaving relation unset.","solutions":["Pass a valid GrammaticalRelation instance (e.g. GrammaticalRelation.valueOf / the appropriate UniversalEnglishGrammaticalRelations constant).","If starting from a string, resolve it explicitly and fail early with a clear message when valueOf returns/throws for an unknown relation.","Fix the Ssurgeon rule so its relation attribute is present and spelled exactly as a valid UD relation.","When auditing AddDep call sites, validate govNodeName, relation, and position together — the constructor checks all three."],"exampleFix":"// before\nnew AddDep(\"gov\", null, attrs, \"+1\"); // throws\n// after\nGrammaticalRelation rel = UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT;\nnew AddDep(\"gov\", rel, attrs, \"+1\");","handlingStrategy":"validation","validationCode":"if (relation == null) throw new IllegalArgumentException(\"AddDep requires a GrammaticalRelation\");","typeGuard":null,"tryCatchPattern":"try { new AddDep(gov, rel, attrs, pos); } catch (SsurgeonParseException e) { throw new IllegalArgumentException(\"AddDep missing relation\", e); }","preventionTips":["Resolve relation strings to GrammaticalRelation explicitly and fail early on unknowns","Validate rule XML relation attribute against the supported UD relation set","Check gov, relation, and position in one validation pass before construction"],"tags":["java","ssurgeon","null-argument","constructor"],"backgroundTag":"null-argument","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"}