Re: [jgrapht-users] Bug in removeAllEdges?
Brought to you by:
barak_naveh,
perfecthash
From: Trevor H. <tr...@vo...> - 2006-11-26 06:51:14
|
On Nov 25, 2006, at 1:24 PM, John V. Sichi wrote: > Trevor Harmon wrote: >> The attached program throws a ConcurrentModificationException, and >> I don't know why. Even stranger, if outgoingEdgesOf is changed to >> edgesOf, the exception is not thrown. Doesn't make sense. Is this >> a bug? > > Not a bug, unless you consider the program below to indicate a bug > in the JDK :) Let me rephrase my question then. The following JDK program works as expected: List<String> list = new ArrayList<String>(); list.add("arm"); list.add("leg"); List<String> sublist = list.subList(0,1); sublist.clear(); But the following JGraphT program throws a ConcurrentModificationException: DirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class); String s1 = "s1"; String s2 = "s2"; g.addVertex(s1); g.addVertex(s2); g.addEdge(s1, s2); g.edgesOf(s1).clear(); Regardless of this problem, how is one supposed to remove all outgoing edges from a vertex? That's all I'm trying to do. With the large number of methods available in JGraphT, I would have expected the API to provide a straightforward way of doing this (without having to iterate over the edges myself). > The outgoingEdgesOf vs edgesOf behavior is just a matter of getting > lucky with one. Well, that part I would still say is a bug. I could understand it if outgoingEdgesOf, incomingEdgesOf, and edgesOf all ended up causing the ConcurrentModificationException -- at least that would be consistent. But that's not the case here. The behavior of an API shouldn't be left to chance. :) Trevor |