zhfeng opened a new pull request, #8508:
URL: https://github.com/apache/camel-quarkus/pull/8508

   ## Summary
   
   Fixes https://github.com/apache/camel-quarkus/issues/7841
   
   Auto-detects exception classes used in `onException()`, `doCatch()`, and 
`throwException()` calls at build time and registers them for GraalVM native 
image reflection. This removes the need for manual `@RegisterForReflection` 
annotations on exception classes referenced in Camel routes.
   
   ### Implementation
   
   Three separate build-time scanners are added, one per DSL:
   
   #### 1. Java DSL — ASM bytecode scanning (`CamelNativeImageProcessor`)
   - Scans `RouteBuilder` class bytecode using ASM 
`ClassVisitor`/`MethodVisitor`
   - Tracks LDC (class constant) instructions followed by method calls to 
`onException`, `doCatch`, `exception`, or `throwException`
   - Validates detected classes are `Throwable` subclasses via Jandex index 
(with `Class.forName()` fallback for JDK classes)
   - Handles both single-arg (`onException(A.class)`) and varargs 
(`onException(A.class, B.class)`) patterns
   
   #### 2. XML DSL — Camel ModelParser (`XmlIoDslProcessor`)
   - Parses XML route files using Camel's `ModelParser` into the route model
   - Walks `RoutesDefinition`, `RouteConfigurationsDefinition`, and 
`ApplicationDefinition` model trees
   - Extracts exception class names from `OnExceptionDefinition`, 
`CatchDefinition`, and `ThrowExceptionDefinition`
   
   #### 3. YAML DSL — SnakeYAML parsing (`YamlDslProcessor`)
   - Parses YAML route files using SnakeYAML Engine into generic Map/List 
structures
   - Recursively walks the parsed YAML looking for 
`onException`/`on-exception`, `doCatch`/`do-catch`, and 
`throwException`/`throw-exception` keys
   - Extracts exception class names from `exception` lists and `exceptionType` 
fields
   
   ### Known concerns
   
   **Java DSL ASM approach fragility:**
   - The bytecode scanner is coupled to Camel method names as strings 
(`onException`, `doCatch`, etc.) and relies on the specific LDC → INVOKE 
bytecode pattern. If Camel renames these methods or changes their signatures in 
the future, the scanner would silently stop detecting exception classes.
   - Different Java compilers or future JDK versions could theoretically emit 
different bytecode sequences for the same source code, which could break 
detection.
   - The XML and YAML parsers do not have this fragility since they use Camel's 
own `ModelParser` and structured YAML parsing, which are stable APIs.
   
   ### Test plan
   
   - [x] Added `XmlOnlyException` — exception class referenced ONLY in XML DSL, 
verifies the XML parser independently
   - [x] Added `YamlOnlyException` — exception class referenced ONLY in YAML 
DSL, verifies the YAML parser independently
   - [x] Existing `RouteConfigurationsException` — referenced in Java DSL, 
verifies the ASM scanner (removed its `@RegisterForReflection`)
   - [x] Removed `@RegisterForReflection` from `EipRoutes` 
(`ThrottlerRejectedExecutionException`) — now auto-detected
   - [x] All 9 tests pass in JVM mode
   - [x] All 9 tests pass in native mode (container build with Mandrel)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Zheng Feng


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