lobtx opened a new pull request, #31195:
URL: https://github.com/apache/camel/pull/31195

   # Description
   
   Follow-up of #30303 and #30400, from the review of #30303.
   
   ## Problem
   
   The options of Camel Main that must be known before the CamelContext is 
built (`camel.main.virtualThreadsEnabled` and 
`camel.main.typeConverterStatisticsEnabled`) are read from the OS environment 
variables and the JVM system properties even when these sources are disabled 
with `camel.main.autoConfigurationEnvironmentVariablesEnabled = false` or 
`camel.main.autoConfigurationSystemPropertiesEnabled = false` in 
`application.properties`.
   
   These two options are applied by the auto configuration 
(`autoConfigurationFailFast`), which runs after the context is built, so the 
early lookup still sees their default value (true).
   
   ## Reproduction
   
   `testSystemPropertyIgnoredWhenSystemPropertiesDisabled` fails on main with 
`expected: <false> but was: <true>`:
   
       System.setProperty("camel.main.typeConverterStatisticsEnabled", "true");
       Main main = new Main();
       
main.addInitialProperty("camel.main.autoConfigurationSystemPropertiesEnabled", 
"false");
       main.start();
       ...
       assertFalse(context.isTypeConverterStatisticsEnabled());
       assertEquals(before, statistics.getAttemptCounter());
   
   Same with a standalone Camel Main application and 
`camel.main.autoConfigurationEnvironmentVariablesEnabled = false` in 
`application.properties`, started with 
`CAMEL_MAIN_TYPECONVERTERSTATISTICSENABLED=true`: the statistics are enabled 
and count the conversions.
   
   ## Why it needs a fix
   
   A source the user disabled is still used, for these options only: every 
other option of Camel Main ignores it.
   
   ## Fix
   
   `loadEarlyProperties` reads the two options from the loaded properties, as 
`autoConfigurationFailFast` does, and only then adds the environment variables 
and the system properties that are enabled. The values are parsed without the 
CamelContext, which is not built yet, so a value with a property placeholder 
cannot be resolved: as for the early options themselves (`lookupEarlyOption`), 
it is ignored with a WARN that tells to use true or false, and the default is 
kept.
   
   Tested with the camel-main tests (367), and with a standalone Camel Main 
application on main and on this branch (10 conversions, counter of the type 
converter registry, also read through JMX):
   
   | | main | this branch |
   |---|---|---|
   | ENV disabled in `application.properties`, 
`CAMEL_MAIN_TYPECONVERTERSTATISTICSENABLED=true` | enabled, 10 | disabled, 0 |
   | SYS disabled in `application.properties`, 
`-Dcamel.main.typeConverterStatisticsEnabled=true` | enabled, 10 | disabled, 0 |
   | ENV or SYS enabled (default), option set there | enabled, 10 | enabled, 10 
|
   | option in `application.properties` | enabled, 10 | enabled, 10 |
   | no option | disabled, 0 | disabled, 0 |
   | ENV or SYS disabled in `application.properties`, 
`virtualThreadsEnabled=true` there | virtual threads | platform threads |
   | ENV or SYS enabled (default), `virtualThreadsEnabled=true` there | virtual 
threads | virtual threads |
   | `autoConfigurationSystemPropertiesEnabled={{sysOn}}` with `sysOn=false` | 
enabled, 10 | enabled, 10, with the WARN |
   
   The flags are honored the same way with `KameletMain`, which `camel run` 
uses.
   
   AI tool used: Claude Code (Claude Opus 5.5), reviewed and checked by me.
   
   _Claude Code on behalf of lobtx_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to