stanfordnlp/CoreNLP · error · SsurgeonParseException

Cannot manually set the index attribute. If you need a…

Error message

Cannot manually set the index attribute.  If you need a moveWord operation, please file an issue on github.

What it means

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.

Solutions

  1. Remove the "idx" key from the attributes map passed to AddDep.
  2. Filter attributes through a whitelist of editable keys (lemma, pos, word, feats, etc.) before constructing AddDep.
  3. 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.

Example fix

// before
Map<String, String> attrs = new HashMap<>();
attrs.put("idx", "5");
attrs.put("lemma", "dog");
new AddDep("root", "dep", attrs, "newnode");

// after
Map<String, String> attrs = new HashMap<>();
attrs.put("lemma", "dog");
new AddDep("root", "dep", attrs, "newnode");
Defensive patterns

Strategy: validation

Validate before calling

// Java
if (attributes.containsKey("idx")) {
  throw new IllegalArgumentException("idx is managed by SemanticGraph and cannot be set via AddDep");
}

Try / catch

// Java
try {
  new AddDep("root", "dep", attrs, "newnode");
} catch (SsurgeonParseException e) {
  log.severe("Illegal AddDep attributes: " + e.getMessage());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/6e401f31f0804734. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java:156

    sg.addEdge(govNode, newNode, relation, weight, false);

    if (position != null && !position.equals("+")) {
      // the payoff for tempIndex == maxIndex + 2:
      // everything will be moved one higher, unless it's the new node
      SsurgeonUtils.moveNodes(sg, sm, x -> (x >= newIndex && x != tempIndex), x -> x+1, true);
      SsurgeonUtils.moveNode(sg, sm, newNode, newIndex);
    }

    return true;
  }

  /**
   * Certain attributes cannot be edited, especially docid, sentid, idx,
   * or they mess up the hashmaps in the SemanticGraph
   */
  public static void checkIllegalAttributes(Map<String, String> attributes) {
    if (attributes.containsKey("idx")) {
      throw new SsurgeonParseException("Cannot manually set the index attribute.  If you need a moveWord operation, please file an issue on github.");
    }
    if (attributes.containsKey("sentIndex")) {
      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.");
    }
    if (attributes.containsKey("docID")) {
      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.");
    }

    // if there's an exception, we'll barf when creating the pattern rather than at runtime
    try {
      CoreLabel newNodeObj = fromCheapStrings(attributes);
    } catch (UnsupportedOperationException e) {
      throw new SsurgeonParseException("Unable to process node attribute keys for Ssurgeon operation", e);
    }
  }

  /**
   * Given the keys and values of the CoreAnnotation attributes,

View on GitHub (pinned to 1b7edd19c4)