diff options
author | Sven Gothel <[email protected]> | 2021-06-15 14:56:56 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-06-15 14:56:56 +0200 |
commit | 3c1aa61438d2631776c6f3652d4eefc4bf8fec75 (patch) | |
tree | c92089adb5ea2963bf3358b42b1c383718d048dd | |
parent | ca5da49571242292a0be8ab404c878027ddbbb6a (diff) |
DBTAdapter.printDeviceLists(): Avoid ConcurrentModificationException by using a shallow copy of ArrayList
Actually this was the intention here, but due to mixed C++/Java programming I missed this nuance.
In C++ the simple assignment is sufficient, not in Java.
-rw-r--r-- | java/jau/direct_bt/DBTAdapter.java | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/java/jau/direct_bt/DBTAdapter.java b/java/jau/direct_bt/DBTAdapter.java index dc50c80b..09aec7e1 100644 --- a/java/jau/direct_bt/DBTAdapter.java +++ b/java/jau/direct_bt/DBTAdapter.java @@ -537,7 +537,8 @@ public class DBTAdapter extends DBTObject implements BTAdapter printDeviceListsImpl(); List<WeakReference<BTDevice>> _discoveredDevices; synchronized(discoveredDevicesLock) { - _discoveredDevices = discoveredDevices; + // Shallow (but expensive) copy to avoid java.util.ConcurrentModificationException while iterating: debug mode only + _discoveredDevices = new ArrayList<WeakReference<BTDevice>>(discoveredDevices); } final int sz = _discoveredDevices.size(); BTUtils.fprintf_td(System.err, "- BTAdapter::DiscoveredDevicesJ: %d elements%s", sz, System.lineSeparator()); |