The "correct" method to access edges source and target, according to JGraphT mailing list is to use the method getEdgeSource(E)
and getEdgeTarget(E)
from the interface Interface Graph<V,E>
of org.jgrapht
the modification of the code is then
for(DefaultEdge edge : edges) {
String v1 = g.getEdgeSource(edge);
String v2 = g.getEdgeTarget(edge);
}