Smack-omemo rework #177 - The OmemoService throws Concurrent Modification Exception

OmemoService#removeStaleDevicesFromDeviceList throws ConcurrentModificationException because the method iterates and modifies the deviceList at the same time i.e.

a. for (int deviceId : deviceList.getActiveDevices())
b. deviceList.addInactiveDevice(deviceId)

03-26 10:18:02.565 E/aTalk: [9] org.atalk.crypto.omemo.AndroidOmemoService.initializationFailed().127 OmemoManager init failed
                            java.util.ConcurrentModificationException
                                at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
                                at java.util.HashMap$KeyIterator.next(HashMap.java:814)
                                at org.jivesoftware.smackx.omemo.OmemoService.removeStaleDevicesFromDeviceList(OmemoService.java:1059)
                                at org.jivesoftware.smackx.omemo.OmemoService.deleteStaleDevices(OmemoService.java:1019)
                                at org.jivesoftware.smackx.omemo.OmemoService.cleanUpDeviceList(OmemoService.java:712)
                                at org.jivesoftware.smackx.omemo.OmemoService.refreshAndRepublishDeviceList(OmemoService.java:692)
                                at org.jivesoftware.smackx.omemo.OmemoService.init(OmemoService.java:263)
                                at org.jivesoftware.smackx.omemo.OmemoManager.initialize(OmemoManager.java:250)
                                at org.jivesoftware.smackx.omemo.OmemoManager$2.run(OmemoManager.java:266)
                                at java.lang.Thread.run(Thread.java:818)
1 Like

Good catch. I will fix this :slight_smile:.

Fixed in 5b1d6b7.

1 Like

Thanks, the problem is fixed

1 Like