I have done some more snooping into the cause of this bug after more
direction and advice from Larry.
The LayerManager.addCategory() method calls the
LayerManager.fireCategoryChanged() method. The
LayerManager.fireCategoryChanged() sets up a loop. In each iteration of this
loop the LayerManager.fireLayerEvent() method is called. Each time we call
this method we create a new thread and pass it as an argument to the method.
Each of these created threads calls the categoryChange() method of the
selected LayerListener object. This action is performed for each
LayerListener registered with the LayerManager.
Larry suggested that the bug might not be a problem becuase the
LayerManager.fireLayerEvent() method schedules the thread for execution on
the Java's AWT Event Dispatch Thread. This means that each thread is
executed sequentially, becuase that's how the AWT Event Dispatch Thread
works.
I think we might still be missing something. In the
LayerManager.fireCategoryChanged method we use an iteration over the
layerListeners collection to control the loop. This means that we are
iterating over the collection before we call the LayerManager.fireLayerEvent()
method is called, and consequently are accessing the layerListener
collection OUTSIDE of the AWT Event Dispatch Thread.
Note what the Javadoc for the ConcurrentModificationException thread states:
"it is not generally permssible for one thread to modify a Collection while
another thread is iterating over it. In general, the results of the
iteration are undefined under these circumstances. Some Iterator
implementations (including those of all the collection implementations
provided by the JRE) may choose to throw this exception if this behavior is
detected."
If the act of iteration over a standard Java collection is included in the
behaviors that are "not generally permissable" then we can still have a
situation where the ConcurrentModificationException is thrown. This would
happen if:
The second call to the LayerManager.addCategory() method causes the
layerListener collection to be iterated over while the iteration over the
same collection is still being executed by the first call to the
LayerManager.addCategory() method.
If the act of iteration over the collection itself is a "generally
permissable" behavior and not considered modification of the collection then
there is no problem and no bug. It is hard to answer this question for sure
unless we know if [1] this class has been modified to fix this problem since
Pedro filed his bug report, or [2] someone can clarify the behavior of the
Java platform and wether iteration is or is not a "generally permissable"
behavior.
I would greatly welcome more comments on this issue from Larry or other Java
programmers more experienced than myself.
Thanks a lot.
The Sunburned Surveyor
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel