stanfordnlp/CoreNLP · error · IllegalArgumentException

No SemanticGraph vertex with index + index + and…

Error message

No SemanticGraph vertex with index  + index +  and copyCount  + copyCount

What it means

SemanticGraph.getNodeByIndexAndCopyCount resolves a vertex by both its index and its copyCount (used for copied nodes, e.g. enhanced/copy edges produced by Universal Dependencies 'copy' annotations) and throws IllegalArgumentException when no vertex matches both values. The Safe variant returns null instead of throwing.

Solutions

  1. Call getNodeByIndexAndCopyCountSafe and handle null
  2. Enumerate copyCounts(graph.getNodeByIndexSafe(index)) to see which copyCounts actually exist before requesting
  3. Confirm the input graph is an enhanced/copy-annotated graph; on basic graphs copyCount semantics do not apply
  4. Regenerate indices/copyCounts from the same parse run rather than caching them across parses

Example fix

// before
IndexedWord node = graph.getNodeByIndexAndCopyCount(idx, copy);
// after
IndexedWord node = graph.getNodeByIndexAndCopyCountSafe(idx, copy);
if (node == null) { /* fall back to getNodeByIndexSafe(idx) or skip */ }
Defensive patterns

Strategy: validation

Validate before calling

boolean hasIndexCopy(SemanticGraph g, int idx, int copy) {
  return g.getNodeByIndexAndCopyCountSafe(idx, copy) != null;
}

Type guard

IndexedWord node = graph.getNodeByIndexAndCopyCountSafe(index, copyCount);
if (node == null) {
  node = graph.getNodeByIndexSafe(index); // graceful fallback
}

Try / catch

try {
  IndexedWord n = graph.getNodeByIndexAndCopyCount(idx, copy);
} catch (IllegalArgumentException e) {
  // inspect copyCounts(vertexSet()) to see valid copyCounts
}

Prevention

When it happens

Trigger: Calling getNodeByIndexAndCopyCount(index, copyCount) where the graph contains a node with that index but a different copyCount, or where no copied node exists at all (copyCount not in the graph's copyCounts(vertex) set).

Common situations: Reading enhanced UD graphs with copy nodes using a copyCount that was valid in a previous parse; assuming copyCount starts at a different value than the library uses; graphs built from CoNLL data that dropped copy annotations.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:632

   */
  public IndexedWord getNodeByIndexSafe(int index) {
    for (IndexedWord vertex : vertexSet()) {
      if (vertex.index() == index) {
        return vertex;
      }
    }
    return null;
  }

  /**
   * Returns the <em>first</em> {@link edu.stanford.nlp.ling.IndexedWord
   * IndexedWord} in this {@code SemanticGraph} having the given integer index,
   * or throws {@code IllegalArgumentException} if no such node is found.
   */
  public IndexedWord getNodeByIndexAndCopyCount(int index, int copyCount) throws IllegalArgumentException {
    IndexedWord node = getNodeByIndexAndCopyCountSafe(index, copyCount);
    if (node == null)
      throw new IllegalArgumentException("No SemanticGraph vertex with index " + index + " and copyCount " + copyCount);
    else
      return node;
  }

  /**
   * Same as above, but returns {@code null} if the index does not exist
   * (instead of throwing an exception).
   */
  public IndexedWord getNodeByIndexAndCopyCountSafe(int index, int copyCount) {
    for (IndexedWord vertex : vertexSet()) {
      if (vertex.index() == index && vertex.copyCount() == copyCount) {
        return vertex;
      }
    }
    return null;
  }

  /**

View on GitHub (pinned to 1b7edd19c4)