Fix concurrent modification error during closing of master channel
This is cleaner attempt to fix the problem as it is in done in #06f1c301b5db8.
This variant does not expose some internal API to the caller, but fixes the
concurrent modification problem by working on a copy of the list while iterating.
package org.openecard.ifd.scio.wrapper;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeMap;
@@ -123,7 +124,8 @@ public class ChannelManager {
public synchronized void closeMasterChannel(String ifdName) {
Set<byte[]> slotHandles = ifdNameToHandles.get(ifdName);
if (slotHandles != null) {
- for (byte[] slotHandle : slotHandles) {
+ // iterate over copy of the list as the closeSlaveHandle call modifies the original slotHandles list
+ for (byte[] slotHandle : Collections.unmodifiableCollection(slotHandles)) {
try {
closeSlaveChannel(slotHandle);
} catch (NoSuchChannel | SCIOException ex) {
