davsclaus opened a new pull request, #29575: URL: https://github.com/apache/camel/pull/29575
# Description JIRA: https://issues.apache.org/jira/browse/CAMEL-26741 Follow-up to #29525. That PR leaves a `VirtualMachineError` (`OutOfMemoryError`, `StackOverflowError`, `InternalError`) from a plain `Processor` as before: it is not set on the exchange but thrown on after the callback, so Camel's error handling does not get a JVM-level failure. Every other `Error` fails the exchange. A plain bean method did the opposite. Reflection wraps any `Throwable` in an `InvocationTargetException`, and `MethodInfo` set its target on the exchange. So `onException`, `doCatch`, redelivery and the dead letter channel also handled an `OutOfMemoryError` from a bean method, but not from a bean that implements `Processor`. | Thrown from | Other `Error`s | `VirtualMachineError` | |---|---|---| | A `Processor` / a bean that is a `Processor` (#29525) | fail the exchange, error handler | thrown on after the callback, no error handler | | A bean method, before this PR | fail the exchange, error handler | **fail the exchange, error handler** | | A bean method, with this PR | fail the exchange, error handler | thrown on after the callback, no error handler | ## Changes - `MethodInfo` (the invocation of a bean method): a `VirtualMachineError` is thrown on after calling the callback, as the `Processor` adapters do. Any other `Error` still fails the exchange. - An `Error` thrown outside the reflective call, such as from a `Callable` that the bean method returned, is now set on the exchange directly (`catch (Throwable)` instead of `catch (Exception)`). Before, it escaped before the callback, and `CamelInternalProcessor` took over. - The 4.24 upgrade guide has a new `camel-bean` entry. ## Tests `BeanMethodThrowsErrorTest` (camel-core) mirrors `ProcessorThrowsErrorTest` from #29525 for bean methods: - an `Error` fails the exchange, and `onException` handles it; - an `Error` from a returned `Callable` fails the exchange; - a `StackOverflowError` is not given to `onException`, nor to redelivery or the dead letter channel; - an `OutOfMemoryError` is not caught by `doCatch`; - `BeanProcessor` calls the callback once, for an `Error` and for a `VirtualMachineError` that it then throws on. The four `VirtualMachineError` tests fail without the `MethodInfo` change and pass with it. camel-bean tests (9) and the camel-core bean, `*Error*` and `*Throwable*` tests (959) pass. ## Notes - The change does not depend on #29525: the `Processor` adapters on `main` already throw a `VirtualMachineError` on after the callback. Once #29525 is merged, the "An Error thrown by a processor" table it adds to `error-handler.adoc` can mention bean methods too. - A `CompletionStage` that a bean method returns and that completes with an `Error` still sets it on the exchange (asynchronous, not changed here). _Claude Code on behalf of davsclaus_ 🤖 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]
