diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c44a1d4c..f213c0c30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ ### Development Bug Fixes: + - Fix ConcurrentModificationException crashing app on Android 8 when monitored regions are + changed at the same time the app shifts from active scanning to passive scanning. + (#578, David G. Young) - Fix ConcurrentModifictionExceptions starting ScanJobs. (#584, #588, David G. Young) - Fix NullPointerException when BluetoothLeScanner cannot be obtained. (#583, David G. Young) + ### 2.12.2 / 2017-08-31 [Full Changelog](https://github.com/AltBeacon/android-beacon-library/compare/2.12.1...2.12.2) diff --git a/src/main/java/org/altbeacon/beacon/service/ScanJob.java b/src/main/java/org/altbeacon/beacon/service/ScanJob.java index db2d104b4..f97770bc8 100644 --- a/src/main/java/org/altbeacon/beacon/service/ScanJob.java +++ b/src/main/java/org/altbeacon/beacon/service/ScanJob.java @@ -17,6 +17,8 @@ import org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator; import org.altbeacon.beacon.logging.LogManager; import org.altbeacon.beacon.utils.ProcessUtils; + +import java.util.ArrayList; import java.util.List; @@ -103,7 +105,9 @@ public void run() { private void startPassiveScanIfNeeded() { LogManager.d(TAG, "Checking to see if we need to start a passive scan"); boolean insideAnyRegion = false; - for (Region region : mScanState.getMonitoringStatus().regions()) { + // Clone the collection before iterating to prevent ConcurrentModificationException per #577 + List regions = new ArrayList<>(mScanState.getMonitoringStatus().regions()); + for (Region region : regions) { RegionMonitoringState state = mScanState.getMonitoringStatus().stateOf(region); if (state != null && state.getInside()) { insideAnyRegion = true;