{"record":{"id":"a97081de89fe4ffe","repo":"stanfordnlp/CoreNLP","slug":"unknown-position-position-in-adddep-operation","errorCode":null,"errorMessage":"Unknown position ${position} in AddDep operation","messagePattern":"Unknown position (.+?) in AddDep operation","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java","lineNumber":39,"sourceCode":" * @author Eric Yeh\n *\n */\npublic class AddDep extends SsurgeonEdit {\n  public static final String LABEL = \"addDep\";\n  final Map<String, String> attributes;\n  final GrammaticalRelation relation;\n  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  /**","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java#L21-L57","documentation":"The AddDep Ssurgeon operation constructor validates its 'position' argument, which must be an offset string starting with '-' (insert before the governor) or '+' (insert after). Any other non-null position string is rejected at construction time with this SsurgeonParseException, before the operation ever runs.","triggerScenarios":"Constructing new AddDep(govNodeName, relation, attributes, position[, weight]) with a position string that does not start with '-' or '+', e.g. \"after\", \"0\", \"before\", or a stray space-prefixed value; also reached when Ssurgeon parses an AddDep element whose position attribute is misspelled or in the wrong format.","commonSituations":"Hand-editing Ssurgeon XML/rule files where the position attribute was written as a word instead of a signed offset; generated rules with a bad default; confusion between index-based insertion and the +/- relative-position convention.","solutions":["Use a signed offset string: pass null for default placement, or values like \"-1\" / \"+1\" (and generally -N/+N) for relative positions.","If you do not need a relative position, pass null for position — the null check is skipped and AddDep falls back to computing an index (maxIndex + 1).","Trim and normalize the position attribute when reading it from config before constructing AddDep.","Wrap construction in try/catch for SsurgeonParseException and surface the bad rule/element to the rule author."],"exampleFix":"// before\nnew AddDep(\"gov\", rel, attrs, \"after\"); // throws\n// after\nnew AddDep(\"gov\", rel, attrs, \"+1\"); // or null for default placement","handlingStrategy":"validation","validationCode":"if (position != null && !(position.startsWith(\"-\") || position.startsWith(\"+\")))\n  throw new IllegalArgumentException(\"position must start with '-' or '+' (or be null): \" + position);","typeGuard":null,"tryCatchPattern":"try { new AddDep(gov, rel, attrs, position); } catch (SsurgeonParseException e) { throw new IllegalArgumentException(\"Bad AddDep position: \" + position, e); }","preventionTips":["Only pass signed offset strings or null for position","Normalize/trim the position attribute read from rule XML before constructing","Validate all AddDep constructor args (position, gov, relation) together in a rule loader"],"tags":["java","ssurgeon","validation","constructor"],"backgroundTag":"invalid-argument-value","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"}