google-maps-clustering icon indicating copy to clipboard operation
google-maps-clustering copied to clipboard

Fix the java.util.ConcurrentModificationException

Open coffeeplanter opened this issue 7 years ago • 5 comments

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)

coffeeplanter avatar Feb 24 '18 19:02 coffeeplanter

Thank you, sorry for the delay. I will take a look asap.

makovkastar avatar Mar 06 '18 10:03 makovkastar

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.

makovkastar avatar Mar 06 '18 15:03 makovkastar

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.

coffeeplanter avatar Mar 07 '18 17:03 coffeeplanter

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.

Merrrrrid avatar Jun 07 '19 07:06 Merrrrrid

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.

marekdef avatar Feb 20 '20 20:02 marekdef