allthingssecurity opened a new pull request, #29898: URL: https://github.com/apache/camel/pull/29898
# Description [CAMEL-26907](https://issues.apache.org/jira/browse/CAMEL-26907) Follow-up of #29525 (CAMEL-26741, an `Error` of a processor fails the exchange), #29665 (CAMEL-26824) and #29668 (CAMEL-26866): the advices of a route and `SharedCamelInternalProcessor`, listed as a follow-up in #29668. The advices of `CamelInternalProcessor` and the code around them caught only `Exception`, so an `Error` that is not a `VirtualMachineError` (such as a `NoClassDefFoundError` of the data format of a Rest DSL binding) escaped: - from the loop over the `before` of the advices of a route or of a step (the binding of the Rest DSL, the Rest OpenAPI and Postman advices, `variableReceive`, the unit of work, ...): the `after` of the advices that already ran did not run, so the unit of work did not end and the exchange stayed inflight; - from `AdviceIterator.runAfterTask`, which runs each `after` and keeps the exception of one so the others still run: an `Error` skipped the `after` of the advices before it, among them the end of the unit of work; - from `RoutePolicyAdvice`: an exception of `RoutePolicy.onExchangeBegin` or `onExchangeDone` is logged at WARN and ignored, so the other policies are still called, but an `Error` (such as of a metrics library of a policy) escaped, with the effects above; - from `SharedCamelInternalProcessor`, which runs the sends of a `ProducerTemplate`: its advice `before`, the producer of a transacted send (whose callback was not called in `finally`), and the result processor (as `asyncRequestBody(uri, body, type)` uses to convert the body): an `Error` there skipped the end of the unit of work and the callback, so an asynchronous send could never complete when the endpoint answered on another thread (with an endpoint that answers on the calling thread, such as `direct`, the future completed with the `Error`). In each case the `Error` reached the caller (the consumer, or the sender) instead of failing the exchange. Change: these catches leave a `VirtualMachineError` as before (thrown on) and handle any other `Throwable` as an exception: the exchange fails with it (wrapped in a `CamelExecutionException`, as for the processors since #29525), and the `after` of the other advices still run; for a route policy it is logged at WARN and ignored, as an exception is. The transacted send of `SharedCamelInternalProcessor` calls its callback in `finally`, as `CamelInternalProcessor.processTransacted` does since #29668 (a `VirtualMachineError` is thrown on after it). The on completions of the unit of work (`UnitOfWorkHelper`) have the same gap; they are in the separate PR of CAMEL-26908 (other files). Not changed here: - `DefaultDebugger` still ignores an exception of a breakpoint. An `Error` of a breakpoint (such as an assertion in `debugBefore`/`debugAfter` of camel-test) now fails the exchange at that step, through the advice loop of the step (`DefaultChannel` is a `CamelInternalProcessor`), as an `Error` of a processor does since #29525. For a test this is the better outcome (`sendBody` still throws it, in a `CamelExecutionException`). As for an exception of an advice, the error handler of the route does not get it; - a data format `Error` in the binding of the Rest DSL now fails the exchange as a server error (500), where an exception of the unmarshal is a bad request (400): an `Error` is not caused by the request; - `DefaultRestOpenapiProcessorStrategy` and `DefaultRestPostmanProcessorStrategy` still catch only `Exception` around `binding.after` in the callback of their producer (component follow-up); - the `before` catch of `SharedCamelInternalProcessor` (its advice is the unit of work of the send) is changed as the others, without a test of its own. Tests: - `CamelInternalProcessorAdviceTest` (which has the exception cases of CAMEL-24978): + an advice whose `before` throws an `AssertionError` (the exchange fails with it, the earlier stateful advice gets its `after`, nothing stays inflight); + an advice whose `after` throws one (the `after` of the earlier advices still run); + the same with a route that failed with an exception (the `Error` is added as suppressed); + a route policy whose `onExchangeBegin`, or `onExchangeDone`, throws one (ignored, the next policy is still called, nothing stays inflight); - new `SharedCamelInternalProcessorThrowsErrorTest`: the result processor of an asynchronous template send throws an `AssertionError`, with an endpoint that answers on the calling thread and with one that answers on another thread (the future completes with the failed exchange; before, the second did not complete within 10 seconds), and of a synchronous send (the send returns the failed exchange); nothing stays inflight; a producer throws one in a transacted send; controls: the result processor throws an exception, and a producer throws an `Error` in a send that is not transacted (the adapter of #29525 handles it). Without the change the nine `Error` tests fail on main (the `Error` reaches the caller, or the asynchronous send does not complete); the two controls pass. With the change they pass, the internal processor, route policy, Rest binding, producer template and debugger tests of camel-core pass (231 run, 0 failures, 3 skipped), 20 runs of the two test classes in one JVM pass (280/280), and the camel-core tests pass (9227 run, 0 failures; 11 errors, all `DumpModelAsYaml*`/`DumpModel*` tests that fail with `NoClassDefFoundError: OgnlExpression` from a stale camel-yaml-io jar in my local repository, unrelated). Upgrade guide: a 4.24 section "an Error of an advice of a route, a route policy or the result processor of a send", as the caller no longer gets such an `Error` (it names the debugger of camel-test, and the transacted send). # 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): [CAMEL-26907](https://issues.apache.org/jira/browse/CAMEL-26907). # 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. (I built the core modules with the formatter and import-sort plugins and ran the camel-core tests. I did not run the full root build.) # 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. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
