You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by tj...@apache.org on 2022/02/01 18:13:54 UTC
[felix-dev] branch master updated: [FELIX-6501] Fixed issue with ConcurrentModificationException
This is an automated email from the ASF dual-hosted git repository.
tjwatson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 65c7d77 [FELIX-6501] Fixed issue with ConcurrentModificationException
new 6d19201 Merge pull request #128 from amitjoy/bugfix/FELIX-6501
65c7d77 is described below
commit 65c7d7704996b5c656447ec425c83093a15a52df
Author: Amit Kumar Mondal <ad...@amitinside.com>
AuthorDate: Tue Feb 1 17:03:12 2022 +0100
[FELIX-6501] Fixed issue with ConcurrentModificationException
---
.../org/apache/felix/scr/impl/manager/ComponentContextImpl.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
index ff0616b..4ca1d85 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
@@ -19,11 +19,11 @@
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));
}
}