Dear,

In the latest version of jgrapht (and perhaps also in other versions), the getEdgeWeight(E e) function is implemented as follows:

public double getEdgeWeight(E e)
    {
        if (e instanceof DefaultWeightedEdge) {
            return ((DefaultWeightedEdge) e).getWeight();
        } else {
            return WeightedGraph.DEFAULT_EDGE_WEIGHT;
        }
    }


If e==null, i.e. the edge does not exist, then this function will return DEFAULT_EDGE_WEIGHT. This is strange as often invoking the getEdgeWeight function on a non-existing edge is simply a bug. 

I would suggest to modify the above function to something like:
public double getEdgeWeight(E e)
    {
        if (e instanceof DefaultWeightedEdge) {
            return ((DefaultWeightedEdge) e).getWeight();
        } else if(e==null){
           throw new UnsupportedArgumentException("Edge cannot be null");
        }else{
            return WeightedGraph.DEFAULT_EDGE_WEIGHT;
        }
    }

One common error would be something like:
Edge e=graph.getEdge(i,j); //Edge (i,j) is not part of the graph, so e==null;
cost += graph.getEdgeWeight(e); //Correct, does not invoke an exception


At the very least, the javadoc for the getEdgeWeight function should mention the above pitfall by specify that invoking the getEdgeWeight function on null returns WeightedGraph.DEFAULT_EDGE_WEIGHT so it's the user's problem to check whether the edge is not equal to null.

This is just a suggestion. If there is support for this change, I'll make a change request.

br,

Joris