google-maps-clustering
google-maps-clustering copied to clipboard
Fix the java.util.ConcurrentModificationException
Fix the following error when screen rotate while quad tree is building:
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:831)
at net.sharewire.googlemapsclustering.ClusterManager$QuadTreeTask.doInBackground(ClusterManager.java:241)
at net.sharewire.googlemapsclustering.ClusterManager$QuadTreeTask.doInBackground(ClusterManager.java:227)
Thank you, sorry for the delay. I will take a look asap.
I cannot reproduce this issue in the sample project. It seems that in your code you are trying to remove items from the list you passed to ClusterManager.setItems(...). I'm thinking whether there should be a fix in the library or not.
You can check my test project: https://github.com/coffeeplanter/MapTest I've included there your library as modified source code. Try to change back there the code from this pull request, install apk, and rotate the device several times during first data downloading. I think, you'll get the exception. Please note that after download completion data are loaded from the local database, and this exception is not thrown. I was not trying to remove items manually. The current behaviour is caused by the library itself.
I also encountered this problem. I don’t do anything specific with clusters, I give all the guidance to the clusters to the library. This pull request must solve this problem.
I am pretty sure that ConcurrentModification exception is caused by passing a mutable list to setItems. The solution in this PR just hides the problem because if there is a modification of this list the indexes will be different - it's just a matter of luck what we get (I guess is pretty common to extend the list so we will get no crash but we will miss some markers). I think in the project mentioned by @coffeeplanter we passed cachedPoints to onSucccess which is mutated by data download and that might be the reason.