ammachado opened a new pull request, #28814: URL: https://github.com/apache/camel/pull/28814
# Description [CAMEL-26470](https://issues.apache.org/jira/browse/CAMEL-26470), a tier 2 item of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132). `PatternHelper.matchPattern` compiled a regular expression for every name that was not an exact or wildcard match. `removeHeaders("Camel*")`, which the security checklist recommends, therefore compiled one per remaining header on every exchange. A pattern without regex metacharacters cannot match anything beyond those two checks, with one exception: a trailing `*` is also a quantifier, so `Camel*` matches a name equal to `Came`. `matchPattern` now skips the regular expression unless the pattern has metacharacters or the name has exactly that shape. In that case the real regular expression still decides, so ASCII-only case folding is preserved. A compile cache was not used: it would add shared static state, and it would need a bound because a pattern can be dynamic. This means that patterns with metacharacters, such as `Camel.*`, still compile on every call. No result changes, so there is no upgrade guide entry. ## Measurements Standalone harness, not JMH: JDK 25 on macOS arm64, single thread, 4 rounds of 2 million passes, `Camel*` against 12 headers of which 2 match, on the calling thread: | | before | after | |---|---|---| | time per pass | about 650 ns | about 220 ns | | allocated per pass | about 7416 B | about 936 B | The bytes that remain come mostly from the `toLowerCase` calls in the wildcard check, which I left alone because `regionMatches` folds case differently. That attribution is from reading the code, it was not profiled. ## Tests 6 new tests in `PatternHelperTest`. They pass on the old code too, as this change must not alter results. The main one compares `matchPattern` with a copy of the old algorithm over a grid of names and patterns. To check that they can fail, I broke the change in three ways, and each made tests fail: dropping the zero-repeat case (3 failures), ignoring surrogate pairs (2), and leaving `?` out of the metacharacters (2). Verified: `camel-support`, 151 tests, 0 failures, and 99 tests in `camel-core` selected by name (remove headers and properties, patterns, `ExchangeHelper`). The full `camel-core` suite and the component modules were not run locally. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not run from the root folder: I ran `mvn install -Dquickly -pl core/camel-core -am`, and `git status` showed only the two changed files afterwards. # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of Adriano Machado (@ammachado) _This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it._ -- 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]
