This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.22.x by this push:
new 417f559642c CAMEL-20613: set AbstractCamelContext#endpointStrategies
to ConcurrentHashSet to prevent ConcurrentModificationException (#13822)
417f559642c is described below
commit 417f559642c7adbe2d33f7cbb13e41f68926d0be
Author: Bartosz Popiela <[email protected]>
AuthorDate: Thu Apr 18 13:29:44 2024 +0200
CAMEL-20613: set AbstractCamelContext#endpointStrategies to
ConcurrentHashSet to prevent ConcurrentModificationException (#13822)
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.
---
.../main/java/org/apache/camel/impl/engine/AbstractCamelContext.java | 5 ++---
1 file changed, 2 insertions(+), 3 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 5f62e8bd41f..0998ff65850 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
@@ -212,7 +212,7 @@ public abstract class AbstractCamelContext extends
BaseService
int defaultRouteStartupOrder = 1000;
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<>();
@@ -1048,10 +1048,9 @@ public abstract class AbstractCamelContext extends
BaseService
@Override
public void registerEndpointCallback(EndpointStrategy strategy) {
- if (!endpointStrategies.contains(strategy)) {
+ if (endpointStrategies.add(strategy)) {
// let it be invoked for already registered endpoints so it can
// catch-up.
- endpointStrategies.add(strategy);
for (Endpoint endpoint : getEndpoints()) {
Endpoint newEndpoint =
strategy.registerEndpoint(endpoint.getEndpointUri(), endpoint);
if (newEndpoint != null) {