gnodet opened a new pull request, #27409: URL: https://github.com/apache/camel/pull/27409
## What's Changed Fixes two bugs in `MainHelper.java` that together made `CAMEL_COMPONENT_*`, `CAMEL_DATAFORMAT_*` and `CAMEL_LANGUAGE_*` environment variables non-functional since CAMEL-16345 (Camel 3.9). ### Bug 1 — Filter prefix mismatch (all env vars silently ignored) `BaseMainSupport.autoConfigurationFromProperties` called `MainHelper.filterEnvVariables` with lowercase dotted prefixes (`"camel.component."`, `"camel.dataformat."`, `"camel.language."`), but `filterEnvVariables` uppercases every env var key before comparing: ```java final String uk = k.toUpperCase(Locale.US); if (uk.startsWith(prefix)) // prefix is "camel.component." — never starts with 'C' ``` So the filter always returned an empty map, and none of the `CAMEL_COMPONENT_*` / `CAMEL_DATAFORMAT_*` / `CAMEL_LANGUAGE_*` variables were ever picked up. **Fix**: pass uppercase underscore prefixes (`"CAMEL_COMPONENT_"`, `"CAMEL_DATAFORMAT_"`, `"CAMEL_LANGUAGE_"`) — matching what `filterEnvVariables` expects. ### Bug 2 — Non-deterministic name lookup for overlapping catalog names The name-resolution step (`addComponentEnvVariables` etc.) used `stream().filter(k::startsWith).findFirst()` on a `HashSet`. Catalog entries like `CAMEL_COMPONENT_NETTY` / `CAMEL_COMPONENT_NETTY_HTTP` or `CAMEL_LANGUAGE_JS` / `CAMEL_LANGUAGE_JSONPATH` are plain prefixes of one another, so whichever came first in the hash iteration order "won", mapping variables to the wrong component (e.g. `CAMEL_COMPONENT_NETTY_HTTP_MUTE_EXCEPTION` → `camel.component.netty.http-mute-exception`). **Fix**: a new private helper `longestMatch` filters by `k.startsWith(name + "_")` (exact boundary check) and picks the longest matching name with `max(Comparator.comparingInt(String::length))`, giving a deterministic and correct result regardless of iteration order. ### Affected pairs (non-exhaustive) | Kind | Shorter name | Longer name | |------|-------------|-------------| | component | `NETTY` | `NETTY_HTTP` | | component | `SJMS` | `SJMS2` | | component | `FILE` | `FILE_WATCH` | | component | `SQL` | `SQL_STORED` | | component | `REST` | `REST_OPENAPI`, `REST_API`, `REST_POSTMAN` | | component | `HTTP` | `HTTPS` | | component | `FTP` | `FTPS` | | component | `VERTX` | `VERTX_HTTP`, `VERTX_WEBSOCKET` | | component | `ACTIVEMQ` | `ACTIVEMQ6` | | language | `JS` | `JSONPATH` | | dataformat | `AVRO` | `AVROJACKSON` | ### Tests Three new tests added to `MainHelperTest`: - `testLongestMatchComponentEnvVariables` — NETTY_HTTP vs NETTY, SJMS2 vs SJMS, FILE_WATCH vs FILE - `testLongestMatchLanguageEnvVariables` — JSONPATH vs JS - `testLongestMatchDataFormatEnvVariables` — AVROJACKSON vs AVRO All 286 existing camel-main tests pass. ### Upgrade Note Since fix 1 makes variables that were previously silently ignored now take effect, a stray env var for a component not on the classpath or for an unknown option will now fail the startup (unless `autoConfigurationFailFast=false`). This is consistent with the documented behaviour of `autoConfigurationEnvironmentVariablesEnabled`. Fixes https://issues.apache.org/jira/browse/CAMEL-25352 _This PR was prepared by a coding agent (Claude Sonnet 4.6) on behalf of gnodet._ -- 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]
