Search code examples
androidaltbeaconandroid-ble

ConcurrentModificationException in ScanJob from android-beacon-library


I've an app scanning for BLE devices. In Crashlytics, I noticed the following crash:

Fatal Exception: java.util.ConcurrentModificationException
       at java.util.ArrayList$Itr.next + 860(ArrayList.java:860)
       at org.altbeacon.beacon.service.ScanJob$1.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$000 + 40(ParseCommandCache.java:40)
       at com.parse.ParseCommandCache$2.run + 188(ParseCommandCache.java:188)

The crash seems to only occurs on device running Android 8+

Has anyone encountered this error and know how to fix it ?

The app uses the lib org.altbeacon:android-beacon-library version 2.16.3


Solution

  • This appears to be a rare bug in the library that will crash during a race condition when a new background scan result delivered by intent in the background. The collection in this method must be copied before being returned to fix the bug:

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

    Please open a new issue on the library's GitHub repo (follow that link) and paste a link to this question. We will fix in the next library version.