来自 android-beacon-library 的 ScanJob 中的 ConcurrentModificationException

ConcurrentModificationException in ScanJob from android-beacon-library

我有一个应用正在扫描 BLE devices。在 Crashlytics 中,我注意到以下崩溃:

Fatal Exception: java.util.ConcurrentModificationException
       at java.util.ArrayList$Itr.next + 860(ArrayList.java:860)
       at org.altbeacon.beacon.service.ScanJob.run + 81(ScanJob.java:81)
       at java.lang.Thread.run + 764(Thread.java:764)

pool-27-thread-2
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor$ + 2137(Thread.java:2137)
       at sun.misc.Unsafe.park + 358(Unsafe.java:358)
       at java.util.concurrent.locks.LockSupport.park + 190(LockSupport.java:190)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await + 2059(AbstractQueuedSynchronizer.java:2059)
       at java.util.concurrent.LinkedBlockingQueue.take + 442(LinkedBlockingQueue.java:442)
       at java.util.concurrent.ThreadPoolExecutor.getTask + 1087(ThreadPoolExecutor.java:1087)
       at java.util.concurrent.ThreadPoolExecutor.runWorker + 1147(ThreadPoolExecutor.java:1147)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run + 636(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run + 764(Thread.java:764)

ParseCommandCache.runLoop()
       at java.lang.Object.wait(Object.java)
       at com.parse.ParseCommandCache.runLoop + 664(ParseCommandCache.java:664)
       at com.parse.ParseCommandCache.access[=11=]0 + 40(ParseCommandCache.java:40)
       at com.parse.ParseCommandCache.run + 188(ParseCommandCache.java:188)

崩溃似乎只发生在设备 运行 Android 8+

有没有人遇到过这个错误并且知道如何修复它?

该应用程序使用库 org.altbeacon:android-beacon-library 版本 2.16.3

这似乎是库中的一个罕见错误,当意图在后台提供新的后台扫描结果时,它会在竞争条件下崩溃。该方法中的集合返回前必须复制,修复bug:

https://github.com/AltBeacon/android-beacon-library/blob/49ebe93a936c406c2fb86a9e3be88908f2e07e4e/lib/src/main/java/org/altbeacon/beacon/service/ScanJobScheduler.java#L76

请在图书馆的 GitHub 存储库上开一个新问题(按照 link)并粘贴 link 到这个问题。我们将在下一个库版本中修复。