stanfordnlp/CoreNLP · error · IllegalArgumentException
No SemanticGraph vertex with index + index
Error message
No SemanticGraph vertex with index + index
What it means
SemanticGraph.getNodeByIndex looks up the vertex whose IndexedWord index equals the given integer and throws IllegalArgumentException when no such node exists. It is the throwing counterpart of getNodeByIndexSafe, which returns null instead.
Solutions
- Call getNodeByIndexSafe(index) first and handle null instead of the throwing variant
- Verify the index exists in the current graph: check vertexSet()/getAllNodesByIndex() before lookup
- Confirm indices match the current tokenization (indices are 1-based per sentence); recompute them after any re-tokenization
- Log the available index range to spot off-by-one or stale-index issues
Example fix
// before
IndexedWord node = graph.getNodeByIndex(idx);
// after
IndexedWord node = graph.getNodeByIndexSafe(idx);
if (node == null) { /* handle missing node */ } Defensive patterns
Strategy: validation
Validate before calling
boolean hasIndex(SemanticGraph g, int idx) {
return g.getNodeByIndexSafe(idx) != null;
} Type guard
IndexedWord node = graph.getNodeByIndexSafe(index); if (node == null) return Optional.empty(); // treat as absent
Try / catch
try {
IndexedWord n = graph.getNodeByIndex(idx);
} catch (IllegalArgumentException e) {
// log index and graph vertex count, fall back to safe lookup
} Prevention
- Prefer *Safe variants whenever absence is a normal condition
- Recompute indices after re-tokenization; never persist them across parses
- Remember indices are 1-based per sentence
- Log graph.getAllNodesByIndex() range on lookup failure
When it happens
Trigger: Calling getNodeByIndex with an index that is not in the graph: stale sentence indices after re-tokenization, 1-based vs 0-based confusion, or a node removed by graph edits/copies (e.g. enhanced graphs, copying, or pruning).
Common situations: Pipeline outputs where the dependency graph excludes punctuation or erased tokens; accessing a governor index from a relation stored earlier after the graph was rebuilt; RTE/QA code (c, hypNode, makeFromIndexArray, newGovernor, pronounCase, testInitialConditions) resolving indices from saved 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
- No SemanticGraph vertex with index + index + and…
- Empty index
- Index outside the bounds
- Index not large enough to name all the array elements!
- Invalid phraseColIndex
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/379a357af9552c42.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:606
*/
public IndexedWord getParent(IndexedWord vertex) {
List<IndexedWord> path = getPathToRoot(vertex);
if (path != null && path.size() > 0)
return path.get(0);
else
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 getNodeByIndex(int index) throws IllegalArgumentException {
IndexedWord node = getNodeByIndexSafe(index);
if (node == null)
throw new IllegalArgumentException("No SemanticGraph vertex with index " + index);
else
return node;
}
/**
* Same as above, but returns {@code null} if the index does not exist
* (instead of throwing an exception).
*/
public IndexedWord getNodeByIndexSafe(int index) {
for (IndexedWord vertex : vertexSet()) {
if (vertex.index() == index) {
return vertex;
}
}
return null;
}
/**View on GitHub (pinned to 1b7edd19c4)