{"record":{"id":"0fc56131b5ecad77","repo":"stanfordnlp/CoreNLP","slug":"path-given-with-missing-edge-connection","errorCode":null,"errorMessage":"Path given with missing edge connection","messagePattern":"Path given with missing edge connection","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/graph/DirectedMultiGraph.java","lineNumber":438,"sourceCode":"      return null;\n\n    if (nodes.size() <= 1)\n      return Collections.emptyList();\n\n    List<E> path = new ArrayList<>();\n    Iterator<V> nodeIterator = nodes.iterator();\n    V previous = nodeIterator.next();\n    while (nodeIterator.hasNext()) {\n      V next = nodeIterator.next();\n      E connection = null;\n      List<E> edges = getEdges(previous, next);\n      if (edges.size() == 0 && !directionSensitive) {\n        edges = getEdges(next, previous);\n      }\n      if (edges.size() > 0) {\n        connection = edges.get(0);\n      } else {\n        throw new IllegalArgumentException(\"Path given with missing \" + \"edge connection\");\n      }\n      path.add(connection);\n      previous = next;\n    }\n    return path;\n  }\n\n  @Override\n  public int getInDegree(V vertex) {\n    if (!containsVertex(vertex)) {\n      return 0;\n    }\n    int result = 0;\n    Map<V, List<E>> incoming = incomingEdges.get(vertex);\n    for (List<E> edges : incoming.values()) {\n      result += edges.size();\n    }\n    return result;","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/graph/DirectedMultiGraph.java#L420-L456","documentation":"DirectedMultiGraph.getShortestPathEdges walks a vertex path and, for each consecutive vertex pair, looks up an edge connecting them. If no edge exists between two consecutive vertices (and direction-sensitive lookup fails), the graph cannot reconstruct the edge path and throws IllegalArgumentException. It means the supplied vertex path is not a valid walk in this graph.","triggerScenarios":"Calling getShortestPathEdges(graph, path) where the list of vertices contains two adjacent vertices with no edge between them (wrong direction when directionSensitive is true, or the edge was removed after the path was computed).","commonSituations":"Passing a path computed from a different/modified graph; reversing a path without considering edge direction; concurrent modification of the graph between path computation and edge reconstruction.","solutions":["Verify each consecutive vertex pair in the path has a connecting edge via graph.getEdges(v1, v2) before calling getShortestPathEdges","If edges may be undirected lookups, pass directionSensitive=false","Recompute the path with getShortestPath (BFS) on the same graph instance right before converting","Check for concurrent modification: snapshot the path and edges together"],"exampleFix":"// before\nList<E> edges = graph.getShortestPathEdges(path);\n// after\nfor (int i = 0; i < path.size() - 1; i++) {\n  if (graph.getEdges(path.get(i), path.get(i + 1)).isEmpty())\n    throw new IllegalStateException(\"No edge between \" + path.get(i) + \" and \" + path.get(i + 1));\n}\nList<E> edges = graph.getShortestPathEdges(path);","handlingStrategy":"validation","validationCode":"static <V,E> boolean isWalk(DirectedMultiGraph<V,E> g, List<V> path) {\n  for (int i = 0; i + 1 < path.size(); i++)\n    if (g.getEdges(path.get(i), path.get(i + 1)).isEmpty()) return false;\n  return path.size() > 0;\n}","typeGuard":"if (path == null || path.size() < 2 || !isWalk(graph, path)) throw new IllegalStateException(\"path is not a walk in this graph\");","tryCatchPattern":"try { return graph.getShortestPathEdges(path); }\ncatch (IllegalArgumentException e) { log.warn(\"Path not a valid walk: {}\", path, e); return Collections.emptyList(); }","preventionTips":["Always derive the path from the same graph instance you convert it on","Validate consecutive-pair edges before conversion","Watch for graph mutations between path computation and use"],"tags":["graph","illegal-argument","path-validation"],"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"}