{"record":{"id":"35f1526ef6ae1b68","repo":"stanfordnlp/CoreNLP","slug":"cannot-manually-change-a-document-id-if-you-need","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java","lineNumber":162,"sourceCode":"      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,\n   * build a CoreLabel to use as the new word\n   */\n  public static CoreLabel fromCheapStrings(Map<String, String> attributes) {\n    String[] keys = new String[attributes.size()];\n    String[] values = new String[attributes.size()];\n    int idx = 0;","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java#L144-L180","documentation":"The third guarded key is \"docID\": a node's document identifier is sentence-level metadata that the SemanticGraph relies on, so per-node edits are forbidden. checkIllegalAttributes throws SsurgeonParseException when the attributes map contains \"docID\".","triggerScenarios":"An AddDep edit whose attributes map includes key \"docID\"; thrown at rule-construction time from AddDep.checkIllegalAttributes.","commonSituations":"Bulk-copying CoreLabel annotations into AddDep attributes; attempting per-token document renaming inside Ssurgeon instead of rewriting document metadata at the document level.","solutions":["Remove \"docID\" from the attributes map.","Rename the document by updating the docID on the sentence/annotation object before Ssurgeon processing, not via node attributes.","Sanitize attribute maps with a filter that drops docID, sentIndex, and idx before constructing Ssurgeon operations."],"exampleFix":"// before\nattrs.put(\"docID\", \"doc-42\");\nattrs.put(\"lemma\", \"run\");\n\n// after\nattrs.remove(\"docID\"); // change docID at the sentence/document level instead\nattrs.put(\"lemma\", \"run\");","handlingStrategy":"validation","validationCode":"// Java\nSet<String> forbidden = Set.of(\"idx\", \"sentIndex\", \"docID\");\nattrs.keySet().removeAll(forbidden); // or reject if present","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  AddDep.checkIllegalAttributes(attrs);\n} catch (SsurgeonParseException e) {\n  // drop the offending metadata key and retry with content attributes only\n}","preventionTips":["Change docID at the document/sentence level, not through node attributes.","Sanitize any attribute map derived from a CoreLabel before feeding it into Ssurgeon rules."],"tags":["java","ssurgeon","validation","metadata"],"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"}