Fixed issue with ConcurrentModificationException
package org.apache.felix.scr.impl.manager;
-import java.util.Collections;
+import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
-import java.util.TreeMap;
+import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -334,6 +334,9 @@ public class ComponentContextImpl<S> implements ScrComponentContext {
private Map<RefPair<?, ?>, Object> createNewFieldHandlerMap()
{
- return Collections.synchronizedMap(new TreeMap<>((o1, o2) -> o1.getRef().compareTo(o2.getRef())));
+ // it's not safe to use synchronized map to prevent concurrent modification exceptions
+ // hence, concurrent collection is used as it provides higher concurrency and scalability
+ // while preserving thread safety
+ return new ConcurrentSkipListMap<>(Comparator.comparing(RefPair::getRef));
}
}
