[ 
https://issues.apache.org/jira/browse/CAMEL-25734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-25734.
---------------------------------
    Resolution: Fixed

Fixed by https://github.com/apache/camel/pull/28003 (b5e6edf1cb30 on main): the 
log lines from before the start are added and taken under a lock, so another 
thread that uses the bean introspection while Camel starts (such as the 
camel-cli-connector) no longer breaks the start.

_Claude Code on behalf of davsclaus_

> camel-core - Starting Camel can fail with a ConcurrentModificationException 
> in DefaultBeanIntrospection
> -------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25734
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25734
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> Starting a {{CamelContext}} can fail with a 
> {{ConcurrentModificationException}}:
> {noformat}
> java.util.ConcurrentModificationException
>       at java.base/java.util.ArrayList.forEach(ArrayList.java:1606)
>       at 
> org.apache.camel.impl.engine.DefaultBeanIntrospection.afterPropertiesConfigured(DefaultBeanIntrospection.java:236)
>       at 
> org.apache.camel.impl.engine.DefaultBeanIntrospection.onCamelContextStarted(DefaultBeanIntrospection.java:263)
>       at 
> org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:200)
>       ...
>       at 
> org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2413)
>       at 
> org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:214)
> {noformat}
> {{DefaultBeanIntrospection}} keeps the log lines of the calls made before the 
> start in a plain {{ArrayList}} ({{preStartLogs}}). Any thread that uses the 
> bean introspection adds to it, and {{afterPropertiesConfigured}} iterates it 
> on the thread that starts Camel. When another thread uses the bean 
> introspection at that moment, the start fails.
> The camel-cli-connector is such a thread: {{AbstractCamelContext}} starts it 
> early, so that its status is available while Camel starts, and every 
> {{DefaultCamelContext}} starts it when camel-cli-connector is on the 
> classpath. So any Camel with camel-cli-connector (every {{camel run}}) can 
> fail to start. It happens rarely, as the window is small.
> Found in the tests of camel-jbang-core (CAMEL-25720): with test JVMs that are 
> reused, a {{DefaultCamelContext}} that a test starts failed this way in about 
> one run out of six.
> *Fix:* add to {{preStartLogs}} and take its lines under a lock, and log the 
> lines that were taken after the lock is released.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to