stanfordnlp/CoreNLP · error · IllegalArgumentException

Path given with missing edge connection

Error message

Path given with missing edge connection

What it means

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.

Solutions

  1. Verify each consecutive vertex pair in the path has a connecting edge via graph.getEdges(v1, v2) before calling getShortestPathEdges
  2. If edges may be undirected lookups, pass directionSensitive=false
  3. Recompute the path with getShortestPath (BFS) on the same graph instance right before converting
  4. Check for concurrent modification: snapshot the path and edges together

Example fix

// before
List<E> edges = graph.getShortestPathEdges(path);
// after
for (int i = 0; i < path.size() - 1; i++) {
  if (graph.getEdges(path.get(i), path.get(i + 1)).isEmpty())
    throw new IllegalStateException("No edge between " + path.get(i) + " and " + path.get(i + 1));
}
List<E> edges = graph.getShortestPathEdges(path);
Defensive patterns

Strategy: validation

Validate before calling

static <V,E> boolean isWalk(DirectedMultiGraph<V,E> g, List<V> path) {
  for (int i = 0; i + 1 < path.size(); i++)
    if (g.getEdges(path.get(i), path.get(i + 1)).isEmpty()) return false;
  return path.size() > 0;
}

Type guard

if (path == null || path.size() < 2 || !isWalk(graph, path)) throw new IllegalStateException("path is not a walk in this graph");

Try / catch

try { return graph.getShortestPathEdges(path); }
catch (IllegalArgumentException e) { log.warn("Path not a valid walk: {}", path, e); return Collections.emptyList(); }

Prevention

When it happens

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

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

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/0fc56131b5ecad77. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/graph/DirectedMultiGraph.java:438

      return null;

    if (nodes.size() <= 1)
      return Collections.emptyList();

    List<E> path = new ArrayList<>();
    Iterator<V> nodeIterator = nodes.iterator();
    V previous = nodeIterator.next();
    while (nodeIterator.hasNext()) {
      V next = nodeIterator.next();
      E connection = null;
      List<E> edges = getEdges(previous, next);
      if (edges.size() == 0 && !directionSensitive) {
        edges = getEdges(next, previous);
      }
      if (edges.size() > 0) {
        connection = edges.get(0);
      } else {
        throw new IllegalArgumentException("Path given with missing " + "edge connection");
      }
      path.add(connection);
      previous = next;
    }
    return path;
  }

  @Override
  public int getInDegree(V vertex) {
    if (!containsVertex(vertex)) {
      return 0;
    }
    int result = 0;
    Map<V, List<E>> incoming = incomingEdges.get(vertex);
    for (List<E> edges : incoming.values()) {
      result += edges.size();
    }
    return result;

View on GitHub (pinned to 1b7edd19c4)