{"record":{"id":"379a357af9552c42","repo":"stanfordnlp/CoreNLP","slug":"no-semanticgraph-vertex-with-index-index","errorCode":null,"errorMessage":"No SemanticGraph vertex with index  + index","messagePattern":"No SemanticGraph vertex with index  \\+ index","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/SemanticGraph.java","lineNumber":606,"sourceCode":"   */\n  public IndexedWord getParent(IndexedWord vertex) {\n    List<IndexedWord> path = getPathToRoot(vertex);\n\n    if (path != null && path.size() > 0)\n      return path.get(0);\n    else\n      return null;\n  }\n\n  /**\n   * Returns the <em>first</em> {@link edu.stanford.nlp.ling.IndexedWord\n   * IndexedWord} in this {@code SemanticGraph} having the given integer index,\n   * or throws {@code IllegalArgumentException} if no such node is found.\n   */\n  public IndexedWord getNodeByIndex(int index) throws IllegalArgumentException {\n    IndexedWord node = getNodeByIndexSafe(index);\n    if (node == null)\n      throw new IllegalArgumentException(\"No SemanticGraph vertex with index \" + index);\n    else\n      return node;\n  }\n\n  /**\n   * Same as above, but returns {@code null} if the index does not exist\n   * (instead of throwing an exception).\n   */\n  public IndexedWord getNodeByIndexSafe(int index) {\n    for (IndexedWord vertex : vertexSet()) {\n      if (vertex.index() == index) {\n        return vertex;\n      }\n    }\n    return null;\n  }\n\n  /**","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/SemanticGraph.java#L588-L624","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nIndexedWord node = graph.getNodeByIndex(idx);\n// after\nIndexedWord node = graph.getNodeByIndexSafe(idx);\nif (node == null) { /* handle missing node */ }","handlingStrategy":"validation","validationCode":"boolean hasIndex(SemanticGraph g, int idx) {\n  return g.getNodeByIndexSafe(idx) != null;\n}","typeGuard":"IndexedWord node = graph.getNodeByIndexSafe(index);\nif (node == null) return Optional.empty(); // treat as absent","tryCatchPattern":"try {\n  IndexedWord n = graph.getNodeByIndex(idx);\n} catch (IllegalArgumentException e) {\n  // log index and graph vertex count, fall back to safe lookup\n}","preventionTips":["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"],"tags":["semantic-graph","lookup","index","stale-reference"],"backgroundTag":"record-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}