davsclaus opened a new pull request, #28003: URL: https://github.com/apache/camel/pull/28003
[CAMEL-25734](https://issues.apache.org/jira/browse/CAMEL-25734): **starting Camel could fail with a `ConcurrentModificationException` in `DefaultBeanIntrospection`.** ### The problem ``` 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.DefaultCamelContext.start(DefaultCamelContext.java:214) ``` `DefaultBeanIntrospection` kept the log lines of the calls made before the start in a plain `ArrayList`. Every thread that uses the bean introspection adds to it, and `afterPropertiesConfigured` iterates it on the thread that starts Camel. The camel-cli-connector uses it at the same time: `AbstractCamelContext` starts the connector early, so its status is available while Camel starts, and a `DefaultCamelContext` starts it whenever camel-cli-connector is on the classpath (as with every `camel run`). The window is small, so it is rare. It showed up in the tests of camel-jbang-core once their JVMs were reused (CAMEL-25720): a context that a test started failed this way in about one run out of six. ### The change The lines are added and taken under a lock, and the lines that were taken are logged after it, so a thread that uses the bean introspection while Camel starts no longer breaks the start. ### Tests `DefaultBeanIntrospectionTest`: another thread uses the bean introspection while `afterPropertiesConfigured` logs 10000 earlier lines. It fails at once without the fix (`ConcurrentModificationException`) and passes with it. The bean introspection, property binding and `DefaultCamelContext` tests of camel-core pass (130). With this fix, the parallel tests of camel-jbang-core passed 15 runs out of 15 (8 forks), where they failed about once in six runs before. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DDRLJAyf8cDXSg8iX785My -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
