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

Work on CAMEL-28096 started by Claus Ibsen.
-------------------------------------------
> camel-core - looking up a route configuration by id makes the global route 
> configurations non-global, so a global route configuration is never replaced 
> or removed
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-28096
>                 URL: https://issues.apache.org/jira/browse/CAMEL-28096
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.25.0
>
>
> h3. Problem
> {{DefaultModel.getRouteConfigurationDefinition(id)}} calls 
> {{idOrCreate(NodeIdFactory)}} on every route configuration while it searches 
> ({{core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java:176-191}}).
>  That gives each global route configuration (one without an id) a generated 
> id, such as {{routesConfiguration1}}. A route without a 
> {{routeConfigurationId}} only matches configurations whose id is null or 
> {{*}} ({{RouteDefinitionHelper.routesByIdOrPattern}}), so after the lookup 
> the global configuration no longer applies to routes added later. The 
> fallback at the end of the same method ("a global route configuration that 
> has no ID assigned") can never match either.
> Consequences:
> # Any lookup by id, also of an id that does not exist (for example by 
> tooling), makes the global configurations non-global. Routes added afterwards 
> silently lose the global onException, intercept, onCompletion and error 
> handler.
> # {{removeRouteConfiguration}} of a global configuration removes nothing. The 
> configuration stays, under a generated id.
> # {{RouteConfigurationBuilder.updateRouteConfigurationsToCamelContext}}, 
> which {{DefaultRoutesLoader.updateRoutes}} uses on every route reload, goes 
> through the same lookup:
> #* reloading a file with a named configuration strips the global 
> configurations from the routes added after the reload;
> #* reloading the global configuration itself leaves the old copy in the list 
> under a generated id, one more per reload. Those copies still match routes 
> with {{routeConfigurationId="*"}} or a pattern.
> {{RoutesConfigurationUpdateTest}} does not catch this: it never has a global 
> and a named configuration at the same time, and its global variant passes 
> because the old copy got a generated id.
> h3. Reproducer
> {code:java}
> context.addRoutes(new RouteConfigurationBuilder() {
>     @Override
>     public void configuration() {
>         
> routeConfiguration().onException(Exception.class).handled(true).to("mock:global");
>     }
> });
> // returns null, but the global configuration now has the id 
> routesConfiguration1
> context.getRouteConfigurationDefinition("doesNotExist");
> context.addRoutes(new RouteBuilder() {
>     @Override
>     public void configure() {
>         from("direct:a").throwException(new 
> IllegalArgumentException("Forced"));
>     }
> });
> // sending to direct:a fails: the global onException is not applied
> {code}
> h3. Proposed fix
> * Compare the ids without assigning one (null-safe {{Objects.equals(id, 
> def.getId())}}).
> * Remove a configuration by identity, so an id-less configuration can be 
> replaced and removed.
> * Tests: a lookup does not change a global configuration; updating and 
> removing a global configuration replaces and removes it (the list size stays 
> the same); updating a named configuration next to a global one keeps the 
> global one for the routes added afterwards.
> Found while analysing CAMEL-25142 (late binding of cross-cutting features), 
> with probe tests on main (4a354d948e9c).
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to