{"record":{"id":"6e401f31f0804734","repo":"stanfordnlp/CoreNLP","slug":"cannot-manually-set-the-index-attribute-if-you-n","errorCode":null,"errorMessage":"Cannot manually set the index attribute.  If you need a moveWord operation, please file an issue on github.","messagePattern":"Cannot manually set the index attribute\\.  If you need a moveWord operation, please file an issue on github\\.","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java","lineNumber":156,"sourceCode":"    sg.addEdge(govNode, newNode, relation, weight, false);\n\n    if (position != null && !position.equals(\"+\")) {\n      // the payoff for tempIndex == maxIndex + 2:\n      // everything will be moved one higher, unless it's the new node\n      SsurgeonUtils.moveNodes(sg, sm, x -> (x >= newIndex && x != tempIndex), x -> x+1, true);\n      SsurgeonUtils.moveNode(sg, sm, newNode, newIndex);\n    }\n\n    return true;\n  }\n\n  /**\n   * Certain attributes cannot be edited, especially docid, sentid, idx,\n   * or they mess up the hashmaps in the SemanticGraph\n   */\n  public static void checkIllegalAttributes(Map<String, String> attributes) {\n    if (attributes.containsKey(\"idx\")) {\n      throw new SsurgeonParseException(\"Cannot manually set the index attribute.  If you need a moveWord operation, please file an issue on github.\");\n    }\n    if (attributes.containsKey(\"sentIndex\")) {\n      throw new SsurgeonParseException(\"Cannot manually change the sentence index.  If you need an operation to change an entire sentence's sentIndex, please file an issue on github.\");\n    }\n    if (attributes.containsKey(\"docID\")) {\n      throw new SsurgeonParseException(\"Cannot manually change a document ID.  If you need an operation to change an entire sentence's document ID, please file an issue on github.\");\n    }\n\n    // if there's an exception, we'll barf when creating the pattern rather than at runtime\n    try {\n      CoreLabel newNodeObj = fromCheapStrings(attributes);\n    } catch (UnsupportedOperationException e) {\n      throw new SsurgeonParseException(\"Unable to process node attribute keys for Ssurgeon operation\", e);\n    }\n  }\n\n  /**\n   * Given the keys and values of the CoreAnnotation attributes,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java#L138-L174","documentation":"Ssurgeon's checkIllegalAttributes rejects any attribute map that tries to set the \"idx\" (token index) of a node created by AddDep. Node indices are managed internally by the SemanticGraph's hashmaps, so manually assigning them corrupts graph bookkeeping. The message points users to file a GitHub issue if they genuinely need a moveWord-style operation.","triggerScenarios":"Calling AddDep (directly or via an Ssurgeon rule) whose attributes map contains the key \"idx\"; checkIllegalAttributes is invoked from the AddDep constructor path and throws SsurgeonParseException at rule-construction time.","commonSituations":"Writing an Ssurgeon .ssurgeon edit script and copying attributes from an existing node verbatim (e.g. dumping all CoreAnnotation keys including idx); assuming idx is an editable CoNLL-U-style field; porting scripts from tools that do allow index reassignment.","solutions":["Remove the \"idx\" key from the attributes map passed to AddDep.","Filter attributes through a whitelist of editable keys (lemma, pos, word, feats, etc.) before constructing AddDep.","If repositioning the word in the sentence is the real goal, use the built-in reordering/deletion operations instead, or request a moveWord operation on the Stanford CoreNLP GitHub tracker."],"exampleFix":"// before\nMap<String, String> attrs = new HashMap<>();\nattrs.put(\"idx\", \"5\");\nattrs.put(\"lemma\", \"dog\");\nnew AddDep(\"root\", \"dep\", attrs, \"newnode\");\n\n// after\nMap<String, String> attrs = new HashMap<>();\nattrs.put(\"lemma\", \"dog\");\nnew AddDep(\"root\", \"dep\", attrs, \"newnode\");","handlingStrategy":"validation","validationCode":"// Java\nif (attributes.containsKey(\"idx\")) {\n  throw new IllegalArgumentException(\"idx is managed by SemanticGraph and cannot be set via AddDep\");\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  new AddDep(\"root\", \"dep\", attrs, \"newnode\");\n} catch (SsurgeonParseException e) {\n  log.severe(\"Illegal AddDep attributes: \" + e.getMessage());\n}","preventionTips":["Whitelist editable attribute keys; never copy a CoreLabel's full key set into AddDep attributes.","Always strip idx, sentIndex, and docID from attribute maps built from existing nodes."],"tags":["java","ssurgeon","validation","graph"],"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"}