This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new b97edccf1f50 CAMEL-26907: camel-core - an Error of an advice of a 
route, a route policy or the result processor of a send no longer skips the end 
of the unit of work (#29898)
b97edccf1f50 is described below

commit b97edccf1f50da6224964e7e0e855557c12ed6c1
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Nov 14 15:11:49 2026 +0530

    CAMEL-26907: camel-core - an Error of an advice of a route, a route policy 
or the result processor of a send no longer skips the end of the unit of work 
(#29898)
    
    The advices of CamelInternalProcessor and the code around them caught
    only Exception, so an Error that is not a VirtualMachineError escaped
    from the before loop of the advices, from AdviceIterator.runAfterTask,
    from RoutePolicyAdvice and from SharedCamelInternalProcessor (the sends
    of a ProducerTemplate): the after of the other advices did not run, the
    unit of work did not end, the exchange stayed inflight, and an
    asynchronous send could never complete.
    
    These catches now handle any other Throwable as an exception: the
    exchange fails with it and the other advices still run; for a route
    policy it is logged at WARN and ignored. The transacted send of
    SharedCamelInternalProcessor calls its callback in finally. A
    VirtualMachineError is thrown on as before. The 4.24 upgrade guide has
    the entry.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../apache/camel/impl/engine/AdviceIterator.java   |   8 +-
 .../camel/impl/engine/CamelInternalProcessor.java  |  22 ++-
 .../impl/engine/SharedCamelInternalProcessor.java  |  26 ++-
 .../engine/CamelInternalProcessorAdviceTest.java   | 168 ++++++++++++++++++++
 ...haredCamelInternalProcessorThrowsErrorTest.java | 174 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  14 ++
 6 files changed, 401 insertions(+), 11 deletions(-)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
index 8002a5f0ec24..dfe5a972d1e9 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
@@ -58,8 +58,12 @@ final class AdviceIterator {
     static void runAfterTask(CamelInternalProcessorAdvice task, Object state, 
Exchange exchange) {
         try {
             task.after(exchange, state);
-        } catch (Exception e) {
-            // allow all advices to complete even if there was an exception,
+        } catch (VirtualMachineError e) {
+            // left as before (thrown on)
+            throw e;
+        } catch (Throwable e) {
+            // allow all advices to complete even if there was an exception 
(or an Error, which would otherwise skip
+            // the after of the advices before it, such as the end of the unit 
of work),
             // and do not lose the exception the exchange already failed with
             Exception existing = exchange.getException();
             if (existing == null) {
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
index b217c017c156..ed1933d784e8 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
@@ -424,7 +424,13 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
                 if (task.hasState()) {
                     states[j++] = state;
                 }
-            } catch (Exception e) {
+            } catch (VirtualMachineError e) {
+                // left as before (thrown on), as in DelegateSyncProcessor
+                throw e;
+            } catch (Throwable e) {
+                // also an Error (such as a NoClassDefFoundError of the data 
format of a rest binding): thrown on, it
+                // would skip the after of the advices whose before ran (such 
as the end of the unit of work), and the
+                // exchange would stay inflight
                 return handleException(exchange, originalCallback, e, 
afterTask, i, j);
             }
         }
@@ -568,7 +574,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
     }
 
     private boolean handleException(
-            Exchange exchange, AsyncCallback originalCallback, Exception e, 
CamelInternalTask afterTask,
+            Exchange exchange, AsyncCallback originalCallback, Throwable e, 
CamelInternalTask afterTask,
             int count, int stateCount) {
         // error in before so break out
         exchange.setException(e);
@@ -714,7 +720,11 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
                     if (isRoutePolicyRunAllowed(policy)) {
                         policy.onExchangeBegin(route, exchange);
                     }
-                } catch (Exception e) {
+                } catch (VirtualMachineError e) {
+                    // left as before (thrown on)
+                    throw e;
+                } catch (Throwable e) {
+                    // also an Error, as for an exception: the other policies 
are still called
                     LOG.warn("Error occurred during onExchangeBegin on 
RoutePolicy: {}. This exception will be ignored", policy,
                             e);
                 }
@@ -735,7 +745,11 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
                     if (isRoutePolicyRunAllowed(policy)) {
                         policy.onExchangeDone(route, exchange);
                     }
-                } catch (Exception e) {
+                } catch (VirtualMachineError e) {
+                    // left as before (thrown on)
+                    throw e;
+                } catch (Throwable e) {
+                    // also an Error, as for an exception: the other policies 
are still called
                     LOG.warn("Error occurred during onExchangeDone on 
RoutePolicy: {}. This exception will be ignored",
                             policy, e);
                 }
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
index 918e29bc2f4f..d67f1f622ed1 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
@@ -120,7 +120,11 @@ public class SharedCamelInternalProcessor implements 
SharedInternalProcessor {
         // optimise for loop using index access to avoid creating iterator 
object
         try {
             state = advice.before(exchange);
-        } catch (Exception e) {
+        } catch (VirtualMachineError e) {
+            // left as before (thrown on), as in DelegateSyncProcessor
+            throw e;
+        } catch (Throwable e) {
+            // also an Error: thrown on, the callback would not be called
             return handleException(exchange, originalCallback, e);
         }
 
@@ -134,7 +138,7 @@ public class SharedCamelInternalProcessor implements 
SharedInternalProcessor {
         }
     }
 
-    private static boolean handleException(Exchange exchange, AsyncCallback 
originalCallback, Exception e) {
+    private static boolean handleException(Exchange exchange, AsyncCallback 
originalCallback, Throwable e) {
         exchange.setException(e);
         originalCallback.done(true);
         return true;
@@ -182,10 +186,16 @@ public class SharedCamelInternalProcessor implements 
SharedInternalProcessor {
         }
         try {
             processor.process(exchange);
-        } catch (Exception e) {
+        } catch (VirtualMachineError e) {
+            // left as before (thrown on, now after the callback), as in 
CamelInternalProcessor
+            throw e;
+        } catch (Throwable e) {
+            // also an Error: thrown on, it would skip the callback (the after 
of the advice, such as the end of the unit
+            // of work)
             exchange.setException(e);
+        } finally {
+            callback.done(true);
         }
-        callback.done(true);
         return true;
     }
 
@@ -214,7 +224,13 @@ public class SharedCamelInternalProcessor implements 
SharedInternalProcessor {
             if (resultProcessor != null) {
                 try {
                     resultProcessor.process(exchange);
-                } catch (Exception e) {
+                } catch (VirtualMachineError e) {
+                    // left as before (thrown on)
+                    throw e;
+                } catch (Throwable e) {
+                    // also an Error: thrown on, it would skip the after of 
the advice and the callback, so the exchange
+                    // would stay inflight, and an asynchronous send could 
never complete when the endpoint answered on
+                    // another thread
                     exchange.setException(e);
                 }
             }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelInternalProcessorAdviceTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelInternalProcessorAdviceTest.java
index f7b24a21c2ec..1db06a9539ad 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelInternalProcessorAdviceTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelInternalProcessorAdviceTest.java
@@ -16,22 +16,29 @@
  */
 package org.apache.camel.impl.engine;
 
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.Route;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.spi.CamelInternalProcessorAdvice;
 import org.apache.camel.spi.InternalProcessor;
+import org.apache.camel.support.RoutePolicySupport;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 
 public class CamelInternalProcessorAdviceTest extends ContextTestSupport {
 
     private final AtomicInteger stateAfter = new AtomicInteger();
+    private final CountingPolicy beginCounter = new CountingPolicy();
+    private final CountingPolicy doneCounter = new CountingPolicy();
 
     @Test
     public void testBeforeFailsRunsAfterOfEarlierAdvices() throws Exception {
@@ -124,6 +131,159 @@ public class CamelInternalProcessorAdviceTest extends 
ContextTestSupport {
         assertSame(forced, out.getException());
     }
 
+    @Test
+    public void testBeforeThrowsErrorRunsAfterOfEarlierAdvices() throws 
Exception {
+        AssertionError error = new AssertionError("Forced before");
+        InternalProcessor ip = (InternalProcessor) 
context.getRoute("start").getProcessor();
+        ip.addAdvice(new StatefulAdvice());
+        ip.addAdvice(new CamelInternalProcessorAdvice<Object>() {
+            @Override
+            public Object before(Exchange exchange) {
+                throw error;
+            }
+
+            @Override
+            public void after(Exchange exchange, Object data) {
+                throw new IllegalStateException("Should not run after when 
before failed");
+            }
+
+            @Override
+            public boolean hasState() {
+                return false;
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        // bounded: before, the Error escaped from the route, without the 
after of the earlier advices
+        Exchange out = template.asyncSend("direct:start", e -> 
e.getMessage().setBody("Hello")).get(10, TimeUnit.SECONDS);
+        assertSame(error, assertInstanceOf(CamelExecutionException.class, 
out.getException()).getCause());
+
+        assertMockEndpointsSatisfied();
+        // the exchange must not be left inflight, and the stateful advice 
gets its state
+        assertEquals(0, context.getInflightRepository().size());
+        assertEquals(1, stateAfter.get());
+    }
+
+    @Test
+    public void testAfterThrowsErrorRunsTheOtherAfters() throws Exception {
+        AssertionError error = new AssertionError("Forced after");
+        InternalProcessor ip = (InternalProcessor) 
context.getRoute("start").getProcessor();
+        ip.addAdvice(new StatefulAdvice());
+        ip.addAdvice(new ThrowingAfterAdvice(error));
+
+        Exchange out = template.asyncSend("direct:start", e -> 
e.getMessage().setBody("Hello")).get(10, TimeUnit.SECONDS);
+        assertSame(error, assertInstanceOf(CamelExecutionException.class, 
out.getException()).getCause());
+
+        // the after of the advices before it (run in reverse order) still 
run, such as the end of the unit of work
+        assertEquals(1, stateAfter.get());
+        assertEquals(0, context.getInflightRepository().size());
+    }
+
+    @Test
+    public void testAfterThrowsErrorKeepsRouteException() throws Exception {
+        AssertionError error = new AssertionError("Forced after");
+        InternalProcessor ip = (InternalProcessor) 
context.getRoute("fail").getProcessor();
+        ip.addAdvice(new ThrowingAfterAdvice(error));
+
+        Exchange out = template.asyncSend("direct:fail", e -> 
e.getMessage().setBody("Hello")).get(10, TimeUnit.SECONDS);
+        Exception cause = out.getException();
+        assertInstanceOf(IllegalArgumentException.class, cause);
+        assertEquals("Forced route", cause.getMessage());
+        assertEquals(1, cause.getSuppressed().length);
+        assertSame(error, cause.getSuppressed()[0]);
+        assertEquals(0, context.getInflightRepository().size());
+    }
+
+    @Test
+    public void testRoutePolicyThrowsErrorOnBeginIsIgnored() throws Exception {
+        // as an exception of a route policy: logged, and the other policies 
are still called
+        getMockEndpoint("mock:policy").expectedMessageCount(1);
+
+        Exchange out = template.asyncSend("direct:policyBegin", e -> 
e.getMessage().setBody("Hello"))
+                .get(10, TimeUnit.SECONDS);
+
+        assertNull(out.getException());
+        assertMockEndpointsSatisfied();
+        assertEquals(1, beginCounter.begins.get());
+        assertEquals(1, beginCounter.dones.get());
+        assertEquals(0, context.getInflightRepository().size());
+    }
+
+    @Test
+    public void testRoutePolicyThrowsErrorOnDoneIsIgnored() throws Exception {
+        getMockEndpoint("mock:policy").expectedMessageCount(1);
+
+        Exchange out = template.asyncSend("direct:policyDone", e -> 
e.getMessage().setBody("Hello"))
+                .get(10, TimeUnit.SECONDS);
+
+        assertNull(out.getException());
+        assertMockEndpointsSatisfied();
+        assertEquals(1, doneCounter.begins.get());
+        assertEquals(1, doneCounter.dones.get());
+        assertEquals(0, context.getInflightRepository().size());
+    }
+
+    private static class ThrowingAfterAdvice implements 
CamelInternalProcessorAdvice<Object> {
+        private final Error error;
+
+        ThrowingAfterAdvice(Error error) {
+            this.error = error;
+        }
+
+        @Override
+        public Object before(Exchange exchange) {
+            return null;
+        }
+
+        @Override
+        public void after(Exchange exchange, Object data) {
+            throw error;
+        }
+
+        @Override
+        public boolean hasState() {
+            return false;
+        }
+    }
+
+    private static class ThrowingPolicy extends RoutePolicySupport {
+        private final boolean onBegin;
+
+        ThrowingPolicy(boolean onBegin) {
+            this.onBegin = onBegin;
+        }
+
+        @Override
+        public void onExchangeBegin(Route route, Exchange exchange) {
+            if (onBegin) {
+                throw new AssertionError("Forced onExchangeBegin");
+            }
+        }
+
+        @Override
+        public void onExchangeDone(Route route, Exchange exchange) {
+            if (!onBegin) {
+                throw new AssertionError("Forced onExchangeDone");
+            }
+        }
+    }
+
+    private static class CountingPolicy extends RoutePolicySupport {
+        private final AtomicInteger begins = new AtomicInteger();
+        private final AtomicInteger dones = new AtomicInteger();
+
+        @Override
+        public void onExchangeBegin(Route route, Exchange exchange) {
+            begins.incrementAndGet();
+        }
+
+        @Override
+        public void onExchangeDone(Route route, Exchange exchange) {
+            dones.incrementAndGet();
+        }
+    }
+
     private class StatefulAdvice implements 
CamelInternalProcessorAdvice<String> {
         @Override
         public String before(Exchange exchange) {
@@ -148,6 +308,14 @@ public class CamelInternalProcessorAdviceTest extends 
ContextTestSupport {
 
                 from("direct:fail").routeId("fail")
                         .throwException(new IllegalArgumentException("Forced 
route"));
+
+                from("direct:policyBegin").routeId("policyBegin")
+                        .routePolicy(new ThrowingPolicy(true), beginCounter)
+                        .to("mock:policy");
+
+                from("direct:policyDone").routeId("policyDone")
+                        .routePolicy(new ThrowingPolicy(false), doneCounter)
+                        .to("mock:policy");
             }
         };
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/SharedCamelInternalProcessorThrowsErrorTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/SharedCamelInternalProcessorThrowsErrorTest.java
new file mode 100644
index 000000000000..53ea85d76ae7
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/SharedCamelInternalProcessorThrowsErrorTest.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.engine;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.DefaultAsyncProducer;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultProducer;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+
+/**
+ * An Error that is not a VirtualMachineError, thrown by the result processor 
of a send of a ProducerTemplate, or by a
+ * producer in a transacted send, fails the exchange, as an exception does, 
instead of skipping the end of the unit of
+ * work of the send (and, for an asynchronous send, its answer).
+ */
+class SharedCamelInternalProcessorThrowsErrorTest extends ContextTestSupport {
+
+    private static final String BY_THE_RESULT_PROCESSOR = "Forced by the 
result processor";
+    private static final String BY_THE_PRODUCER = "Forced by the producer";
+
+    private final Processor throwingError = exchange -> {
+        throw new AssertionError(BY_THE_RESULT_PROCESSOR);
+    };
+
+    @Test
+    void testResultProcessorThrowsErrorFailsTheAsyncSend() throws Exception {
+        // as asyncRequestBody(uri, body, type) does, with a result processor 
that converts the body (here the answer
+        // comes on the same thread, and the future completed with the Error 
before)
+        Exchange out = ((DefaultProducerTemplate) 
template).asyncSend(context.getEndpoint("direct:start"),
+                ExchangePattern.InOut, e -> e.getMessage().setBody("Hello"), 
throwingError).get(10, TimeUnit.SECONDS);
+
+        assertFailedWithTheError(out, BY_THE_RESULT_PROCESSOR);
+    }
+
+    @Test
+    void 
testResultProcessorThrowsErrorFailsTheAsyncSendAnsweredOnAnotherThread() throws 
Exception {
+        // the producer answers on another thread: before, the Error was 
thrown on that thread, and the future never
+        // completed
+        Exchange out = ((DefaultProducerTemplate) 
template).asyncSend(context.getEndpoint("fake:answerOnAnotherThread"),
+                ExchangePattern.InOut, e -> e.getMessage().setBody("Hello"), 
throwingError).get(10, TimeUnit.SECONDS);
+
+        assertFailedWithTheError(out, BY_THE_RESULT_PROCESSOR);
+    }
+
+    @Test
+    void testResultProcessorThrowsErrorFailsTheSend() {
+        Exchange out = assertTimeoutPreemptively(Duration.ofSeconds(10),
+                () -> template.send(context.getEndpoint("direct:start"), 
ExchangePattern.InOut,
+                        e -> e.getMessage().setBody("Hello"), throwingError));
+
+        assertFailedWithTheError(out, BY_THE_RESULT_PROCESSOR);
+    }
+
+    @Test
+    void testResultProcessorThrowsExceptionFailsTheSend() {
+        // control: an exception was already set on the exchange
+        IllegalStateException forced = new IllegalStateException("Forced");
+        Exchange out = template.send(context.getEndpoint("direct:start"), 
ExchangePattern.InOut,
+                e -> e.getMessage().setBody("Hello"), e -> {
+                    throw forced;
+                });
+
+        assertSame(forced, out.getException());
+        assertEquals(0, context.getInflightRepository().size());
+    }
+
+    @Test
+    void testProducerThrowsErrorInATransactedSendFailsTheExchange() {
+        Exchange out = assertTimeoutPreemptively(Duration.ofSeconds(10),
+                () -> template.send("fake:throw", e -> 
e.getExchangeExtension().setTransacted(true)));
+
+        assertFailedWithTheError(out, BY_THE_PRODUCER);
+    }
+
+    @Test
+    void testProducerThrowsErrorFailsTheExchange() {
+        // control: not transacted, the adapter of the producer already failed 
the exchange (CAMEL-26741)
+        Exchange out = template.send("fake:throw", e -> 
e.getMessage().setBody("Hello"));
+
+        assertFailedWithTheError(out, BY_THE_PRODUCER);
+    }
+
+    private void assertFailedWithTheError(Exchange out, String message) {
+        Throwable cause = assertInstanceOf(CamelExecutionException.class, 
out.getException()).getCause();
+        assertEquals(message, assertInstanceOf(AssertionError.class, 
cause).getMessage());
+        // the unit of work of the send is done
+        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> 
assertEquals(0, context.getInflightRepository().size()));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                context.addComponent("fake", new FakeComponent());
+
+                from("direct:start").to("mock:result");
+            }
+        };
+    }
+
+    private static final class FakeComponent extends DefaultComponent {
+        @Override
+        protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) {
+            return new FakeEndpoint(uri, this);
+        }
+    }
+
+    private static final class FakeEndpoint extends DefaultEndpoint {
+        FakeEndpoint(String uri, Component component) {
+            super(uri, component);
+        }
+
+        @Override
+        public Producer createProducer() {
+            if (getEndpointUri().endsWith("answerOnAnotherThread")) {
+                // answers on another thread
+                return new DefaultAsyncProducer(this) {
+                    @Override
+                    public boolean process(Exchange exchange, AsyncCallback 
callback) {
+                        new Thread(() -> callback.done(false), 
"answer").start();
+                        return false;
+                    }
+                };
+            }
+            return new DefaultProducer(this) {
+                @Override
+                public void process(Exchange exchange) {
+                    throw new AssertionError(BY_THE_PRODUCER);
+                }
+            };
+        }
+
+        @Override
+        public Consumer createConsumer(Processor processor) {
+            throw new UnsupportedOperationException();
+        }
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 918d791172bc..a6dbbcbb5b8d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -906,6 +906,20 @@ caller), put the EIP in a `doTry` with only a `doFinally` 
in the called route, o
 called route with `errorHandler(noErrorHandler())`, which turns it off for the 
other steps of that route too. Neither
 option brings back the redelivery of a whole routing slip or dynamic router.
 
+=== camel-core - an Error of an advice of a route, a route policy or the 
result processor of a send
+
+An `Error` that is not a `VirtualMachineError` (such as a 
`NoClassDefFoundError` of a data format), thrown by an advice
+of a route or of a step (such as the binding of the Rest DSL, 
`variableReceive`, or the debugger, for example an
+assertion in `debugBefore` or `debugAfter` of camel-test), by the result 
processor of a `ProducerTemplate` send, or by
+the producer of a transacted `ProducerTemplate` send, now fails the exchange 
(wrapped in a `CamelExecutionException`),
+and the advices that already ran end as for an exception (such as the end of 
the unit of work). As for an exception of
+an advice, the error handler of that route does not get it. An `Error` of a 
`RoutePolicy` (`onExchangeBegin`,
+`onExchangeDone`) is logged at WARN and ignored, as an exception already was, 
so an assertion inside a `RoutePolicy`
+no longer fails the caller. Before, the `Error` was thrown on to the code that 
ran the route or the send (such as the
+consumer, or the caller of a `ProducerTemplate`), and the exchange could stay 
inflight (an asynchronous send with a
+result processor could never complete when the endpoint answered on another 
thread). A `VirtualMachineError` is left
+as before.
+
 === camel-core - an AsyncProcessor that throws in a step without an error 
handler fails the exchange
 
 A step that has no error handler of its own (the steps of `doTry`, `doCatch`, 
`doFinally` and `onException`, also when

Reply via email to