This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.4.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.4.x by this push: new 3ccf5409add CAMEL-20613: set AbstractCamelContext#endpointStrategies to ConcurrentHashSet to prevent ConcurrentModificationException (#13821) 3ccf5409add is described below commit 3ccf5409addca5b7eeb7613a70bd7edd5560c2a2 Author: Bartosz Popiela <bartosz...@gmail.com> AuthorDate: Thu Apr 18 13:29:07 2024 +0200 CAMEL-20613: set AbstractCamelContext#endpointStrategies to ConcurrentHashSet to prevent ConcurrentModificationException (#13821) If a thread iterates over the list of strategies while another thread adds a new strategy, ConcurrentModificationException is thrown. To fix this issue, AbstractCamelContext#endpointStrategies can be set to a thread-safe collection. --- .../org/apache/camel/impl/engine/AbstractCamelContext.java | 4 ++-- .../camel/impl/engine/DefaultCamelContextExtension.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index c1aed60c68a..062b07914bf 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -206,7 +206,7 @@ public abstract class AbstractCamelContext extends BaseService private final DefaultCamelContextExtension camelContextExtension = new DefaultCamelContextExtension(this); private final AtomicInteger endpointKeyCounter = new AtomicInteger(); - private final List<EndpointStrategy> endpointStrategies = new ArrayList<>(); + private final Set<EndpointStrategy> endpointStrategies = ConcurrentHashMap.newKeySet(); private final GlobalEndpointConfiguration globalEndpointConfiguration = new DefaultGlobalEndpointConfiguration(); private final Map<String, Component> components = new ConcurrentHashMap<>(); private final Set<Route> routes = new LinkedHashSet<>(); @@ -4203,7 +4203,7 @@ public abstract class AbstractCamelContext extends BaseService return camelContextExtension.getRegistry(); } - List<EndpointStrategy> getEndpointStrategies() { + Set<EndpointStrategy> getEndpointStrategies() { return endpointStrategies; } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java index a5efe918e62..a117db7b378 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java @@ -258,15 +258,17 @@ class DefaultCamelContextExtension implements ExtendedCamelContext { @Override public void registerEndpointCallback(EndpointStrategy strategy) { - if (!camelContext.getEndpointStrategies().contains(strategy)) { - // let it be invoked for already registered endpoints so it can - // catch-up. - camelContext.getEndpointStrategies().add(strategy); + // let it be invoked for already registered endpoints so it can + // catch-up. + if (camelContext.getEndpointStrategies().add(strategy)) { for (Endpoint endpoint : camelContext.getEndpoints()) { - Endpoint newEndpoint = strategy.registerEndpoint(endpoint.getEndpointUri(), endpoint); + Endpoint newEndpoint = strategy.registerEndpoint(endpoint.getEndpointUri(), + endpoint); if (newEndpoint != null) { // put will replace existing endpoint with the new endpoint - camelContext.getEndpointRegistry().put(camelContext.getEndpointKey(endpoint.getEndpointUri()), newEndpoint); + camelContext.getEndpointRegistry() + .put(camelContext.getEndpointKey(endpoint.getEndpointUri()), + newEndpoint); } } }