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 f8c500e20135 CAMEL-26905: camel-core - an Error of the aggregation
strategy of a split or multicast, or of the iterator of a streaming split,
fails the exchange (#29896)
f8c500e20135 is described below
commit f8c500e20135f8afef543991b6d44c52f2c4c82b
Author: allthingssecurity <[email protected]>
AuthorDate: Mon Nov 16 18:58:39 2026 +0530
CAMEL-26905: camel-core - an Error of the aggregation strategy of a split
or multicast, or of the iterator of a streaming split, fails the exchange
(#29896)
[CAMEL-26905](https://issues.apache.org/jira/browse/CAMEL-26905), and since
the review also
[CAMEL-26952](https://issues.apache.org/jira/browse/CAMEL-26952) (the
`onPrepare` processor and the parts of a transacted EIP, folded in)
Follow-up of #29525 (CAMEL-26741) and #29665 (CAMEL-26824), the last item
of the list asked for in the review of #29525. The tasks of
`MulticastProcessor` caught only exceptions where they aggregate
(`aggregateCompleted`, `timeout`) and where they take the next part (`run` of
`MulticastReactiveTask` and `MulticastTransactedTask`). An `Error` that is not
a `VirtualMachineError` (an `AssertionError` of an `AggregationStrategy`, also
of its `timeout`, or of the iterator of a streaming sp [...]
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/processor/MulticastProcessor.java | 61 ++++-
.../camel/processor/RecipientListProcessor.java | 6 +-
.../processor/MulticastTaskThrowsErrorTest.java | 275 +++++++++++++++++++++
.../camel/processor/OnPrepareThrowsErrorTest.java | 134 ++++++++++
.../processor/SiblingProcessorsThrowErrorTest.java | 6 +-
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 20 +-
.../modules/ROOT/pages/error-handler.adoc | 16 +-
7 files changed, 499 insertions(+), 19 deletions(-)
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 26caf83e42fe..ea01a7a57531 100644
---
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -530,6 +530,12 @@ public class MulticastProcessor extends
BaseProcessorSupport
}
} catch (Exception e) {
doFailed(e);
+ } catch (VirtualMachineError e) {
+ // left as before, as in DelegateSyncProcessor
+ throw e;
+ } catch (Throwable e) {
+ // also an Error of the aggregation strategy: thrown on, it
would leave the exchange without its done
+ doFailed(e);
}
}
@@ -583,6 +589,11 @@ public class MulticastProcessor extends
BaseProcessorSupport
doTimeoutDone(result.get(), true);
} catch (Exception e) {
doTimeoutFailed(e);
+ } catch (VirtualMachineError e) {
+ throw e;
+ } catch (Throwable e) {
+ // also an Error of the aggregation strategy
+ doTimeoutFailed(e);
} finally {
lock.unlock();
}
@@ -607,6 +618,14 @@ public class MulticastProcessor extends
BaseProcessorSupport
* completed (for example by the timeout), and handed back to the
caller, is not changed afterwards.
*/
protected void doFailed(Exception e) {
+ doFailed((Throwable) e);
+ }
+
+ /**
+ * Same as {@link #doFailed(Exception)} for any {@link Throwable},
such as an Error that is not a
+ * {@link VirtualMachineError} (set on the exchange wrapped in a
CamelExecutionException).
+ */
+ protected void doFailed(Throwable e) {
if (done.compareAndSet(false, true)) {
cancelTimeoutTask();
original.setException(e);
@@ -620,6 +639,13 @@ public class MulticastProcessor extends
BaseProcessorSupport
* Same as {@link #doFailed(Exception)} but called from the timeout
task, which must not cancel itself.
*/
protected void doTimeoutFailed(Exception e) {
+ doTimeoutFailed((Throwable) e);
+ }
+
+ /**
+ * Same as {@link #doTimeoutFailed(Exception)} for any {@link
Throwable}.
+ */
+ protected void doTimeoutFailed(Throwable e) {
if (done.compareAndSet(false, true)) {
original.setException(e);
MulticastProcessor.this.doDone(original, null, pairs,
callback, false, false);
@@ -628,9 +654,15 @@ public class MulticastProcessor extends
BaseProcessorSupport
}
}
- private void logFailedAfterDone(Exception e) {
- LOG.debug("Exception occurred after the exchange was already
completed, so it is not set on exchange: {}",
- original.getExchangeId(), e);
+ private void logFailedAfterDone(Throwable e) {
+ if (e instanceof Exception) {
+ LOG.debug("Exception occurred after the exchange was already
completed, so it is not set on exchange: {}",
+ original.getExchangeId(), e);
+ } else {
+ // an Error reached the thread before, so it is not only
logged at DEBUG now
+ LOG.warn("Error occurred after the exchange was already
completed, so it is not set on exchange: {}",
+ original.getExchangeId(), e);
+ }
}
private void cancelTimeoutTask() {
@@ -759,6 +791,11 @@ public class MulticastProcessor extends
BaseProcessorSupport
}
} catch (Exception e) {
doFailed(e);
+ } catch (VirtualMachineError e) {
+ throw e;
+ } catch (Throwable e) {
+ // also an Error of the iterator of a streaming split
+ doFailed(e);
}
}
@@ -793,6 +830,12 @@ public class MulticastProcessor extends
BaseProcessorSupport
} catch (Exception e) {
doFailed(e);
return;
+ } catch (VirtualMachineError e) {
+ throw e;
+ } catch (Throwable e) {
+ // also an Error of the iterator
+ doFailed(e);
+ return;
}
}
}
@@ -835,6 +878,12 @@ public class MulticastProcessor extends
BaseProcessorSupport
sync.process(exchange);
} catch (Exception e) {
exchange.setException(e);
+ } catch (VirtualMachineError e) {
+ // left as before (thrown on)
+ throw e;
+ } catch (Throwable e) {
+ // also an Error, as for an exception: only this part fails
(thrown on, it would fail the whole exchange)
+ exchange.setException(e);
} finally {
afterSend(pair, watch, original);
}
@@ -1258,7 +1307,11 @@ public class MulticastProcessor extends
BaseProcessorSupport
if (onPrepare != null) {
try {
onPrepare.process(exchange);
- } catch (Exception e) {
+ } catch (VirtualMachineError e) {
+ // left as before (thrown on)
+ throw e;
+ } catch (Throwable e) {
+ // also an Error, as for an exception: only this part fails
(thrown on, it would fail the whole exchange)
exchange.setException(e);
}
}
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
index 4368fc915064..22564b9e9518 100644
---
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
@@ -373,7 +373,11 @@ public class RecipientListProcessor extends
MulticastProcessor {
if (onPrepare != null) {
try {
onPrepare.process(copy);
- } catch (Exception e) {
+ } catch (VirtualMachineError e) {
+ // left as before (thrown on)
+ throw e;
+ } catch (Throwable e) {
+ // also an Error, as for an exception: only this part fails
(thrown on, it would fail the whole exchange)
copy.setException(e);
}
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastTaskThrowsErrorTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastTaskThrowsErrorTest.java
new file mode 100644
index 000000000000..fe36bd9590d7
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastTaskThrowsErrorTest.java
@@ -0,0 +1,275 @@
+/*
+ * 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.processor;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.spi.CamelEvent.ExchangeCompletedEvent;
+import org.apache.camel.spi.CamelEvent.ExchangeFailedEvent;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.support.service.ServiceHelper;
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Follow-up of CAMEL-26741 and CAMEL-26824: an Error that is not a
VirtualMachineError, thrown by the aggregation
+ * strategy of a split or multicast (also when its timeout is called), or by
the iterator of a streaming split, fails
+ * the exchange once, instead of escaping from the task of the multicast (to
the caller, or lost on a thread of the
+ * pool).
+ */
+class MulticastTaskThrowsErrorTest extends ContextTestSupport {
+
+ private static final AggregationStrategy FAILING = (oldExchange,
newExchange) -> {
+ throw new AssertionError("aggregation failed");
+ };
+
+ // releases the slow part of the timeout test
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @Test
+ void errorOfTheAggregationStrategyOfASplitFailsTheExchange() throws
Exception {
+ assertFailsWithAssertionError("direct:split", false);
+ }
+
+ @Test
+ void errorOfTheAggregationStrategyOfAParallelSplitFailsTheExchange()
throws Exception {
+ assertFailsWithAssertionError("direct:parallelSplit", false);
+ }
+
+ @Test
+ void errorOfTheAggregationStrategyOfAMulticastFailsTheExchange() throws
Exception {
+ assertFailsWithAssertionError("direct:multicast", false);
+ }
+
+ @Test
+ void errorOfTheTimeoutOfTheAggregationStrategyFailsTheExchange() throws
Exception {
+ try {
+ // the slow part is released once the split answered, so it can
end before the inflight check
+ assertFailsWithAssertionError("direct:timeout", false,
release::countDown);
+ } finally {
+ release.countDown();
+ }
+ }
+
+ @Test
+ void errorOfTheIteratorOfAParallelStreamingSplitFailsTheExchange() throws
Exception {
+ assertFailsWithAssertionError("direct:parallelStreamingSplit", false);
+ }
+
+ @Test
+ void errorOfTheIteratorOfAStreamingSplitFailsTheExchange() throws
Exception {
+ assertFailsWithAssertionError("direct:streamingSplit", false);
+ }
+
+ @Test
+ void errorOfAProcessorOfATransactedSplitFailsTheExchange() throws
Exception {
+ // control: the step of the processor handles its Error already
(CAMEL-26741), also in a transacted split
+ assertFailsWithAssertionError("direct:transactedSplit", true);
+ }
+
+ @Test
+ void errorOfTheIteratorOfATransactedStreamingSplitFailsTheExchange()
throws Exception {
+ // the transacted task now fails the exchange itself; without it, the
transacted step around the split
+ // (CAMEL-26866) fails the exchange with the Error too, so this case
passes either way
+ assertFailsWithAssertionError("direct:streamingSplit", true);
+ }
+
+ @Test
+ void errorOfAPartOfATransactedMulticastFailsOnlyThatPart() throws
Exception {
+ assertOnlyTheTransactedPartFails(new AssertionError("part failed"));
+ }
+
+ @Test
+ void exceptionOfAPartOfATransactedMulticastFailsOnlyThatPart() throws
Exception {
+ // control: an exception already failed only the part
+ assertOnlyTheTransactedPartFails(new IllegalArgumentException("part
failed"));
+ }
+
+ private void assertOnlyTheTransactedPartFails(Throwable failure) throws
Exception {
+ // the parts are not wrapped (in a unit of work, an error handler or a
step, which handle an Error already),
+ // so what the first part throws reaches the transacted task, as an
Error that escapes the step of a part does
+ List<String> sent = new CopyOnWriteArrayList<>();
+ Processor first = e -> {
+ if (failure instanceof Error error) {
+ throw error;
+ }
+ throw (Exception) failure;
+ };
+ Processor second = e -> sent.add("second");
+ MulticastProcessor multicast
+ = new MulticastProcessor(context, null, List.of(first,
second), new UseLatestAggregationStrategy()) {
+ @Override
+ protected Processor wrapInErrorHandler(Route route,
Exchange exchange, Processor processor) {
+ return processor;
+ }
+ };
+ ServiceHelper.startService(multicast);
+ try {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getExchangeExtension().setTransacted(true);
+ multicast.process(exchange);
+
+ assertEquals(List.of("second"), sent, "the part after the failed
part must still be sent");
+ assertTrue(causedBy(exchange.getException(), failure.getClass()),
+ "expected " + failure + " in the causes of " +
exchange.getException());
+ } finally {
+ ServiceHelper.stopService(multicast);
+ }
+ }
+
+ private void assertFailsWithAssertionError(String uri, boolean transacted)
throws Exception {
+ assertFailsWithAssertionError(uri, transacted, () -> {
+ });
+ }
+
+ private void assertFailsWithAssertionError(String uri, boolean transacted,
Runnable afterReply) throws Exception {
+ Map<String, AtomicInteger> done = countDoneExchanges();
+ // bounded: before, with parallelProcessing the exchange never
completed
+ Exchange out = template.asyncSend(uri, e -> {
+ e.getMessage().setBody(List.of("a", "b", "c"));
+ e.getExchangeExtension().setTransacted(transacted);
+ }).get(10, TimeUnit.SECONDS);
+
+ afterReply.run();
+ assertNotNull(out.getException(), "the exchange must fail");
+ assertTrue(causedBy(out.getException(), AssertionError.class),
"expected an AssertionError in the causes of "
+ +
out.getException());
+ // the future completes when the callback is called, the unit of work
of the exchange ends right after
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(0,
context.getInflightRepository().size(),
+ "the exchange must not stay inflight"));
+ // done once: a second completion would fire a second event for the
same exchange
+ await().during(200, TimeUnit.MILLISECONDS).atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(1,
done.getOrDefault(out.getExchangeId(), new AtomicInteger()).get()));
+ }
+
+ private Map<String, AtomicInteger> countDoneExchanges() {
+ Map<String, AtomicInteger> done = new ConcurrentHashMap<>();
+ context.getManagementStrategy().addEventNotifier(new
EventNotifierSupport() {
+ @Override
+ public void notify(CamelEvent event) {
+ Exchange exchange = ((CamelEvent.ExchangeEvent)
event).getExchange();
+ done.computeIfAbsent(exchange.getExchangeId(), k -> new
AtomicInteger()).incrementAndGet();
+ }
+
+ @Override
+ public boolean isEnabled(CamelEvent event) {
+ return event instanceof ExchangeCompletedEvent || event
instanceof ExchangeFailedEvent;
+ }
+ });
+ return done;
+ }
+
+ private static boolean causedBy(Throwable t, Class<? extends Throwable>
type) {
+ for (Throwable c = t; c != null; c = c.getCause()) {
+ if (type.isInstance(c)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ errorHandler(noErrorHandler());
+
+ from("direct:split").split(body(),
FAILING).to("mock:part").end();
+ from("direct:parallelSplit").split(body(),
FAILING).parallelProcessing().to("mock:part").end();
+ from("direct:multicast").multicast(FAILING).to("mock:a",
"mock:b").end();
+ from("direct:slow").process(e -> release.await(20,
TimeUnit.SECONDS));
+ // the split is done by its timeout, while the second part
still waits: the timeout of the strategy
+ // throws
+ from("direct:timeout").split(body(), new
TimeoutFailing()).parallelProcessing().timeout(1000)
+ .choice()
+ .when(body().isEqualTo("b")).to("direct:slow")
+ .otherwise().to("mock:part")
+ .end()
+ .end();
+ from("direct:parallelStreamingSplit")
+ .split(method(MulticastTaskThrowsErrorTest.class,
"failingIterator")).streaming()
+ .parallelProcessing()
+ .to("mock:part")
+ .end();
+ from("direct:streamingSplit")
+ .split(method(MulticastTaskThrowsErrorTest.class,
"failingIterator")).streaming()
+ .to("mock:part")
+ .end();
+ from("direct:transactedSplit").split(body())
+ .process(e -> {
+ throw new AssertionError("in a transacted split");
+ })
+ .end();
+ }
+ };
+ }
+
+ /** A strategy that aggregates, and whose timeout throws an
AssertionError. */
+ private static final class TimeoutFailing implements AggregationStrategy {
+ @Override
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ return oldExchange != null ? oldExchange : newExchange;
+ }
+
+ @Override
+ public void timeout(Exchange exchange, int index, int total, long
timeout) {
+ throw new AssertionError("timeout failed");
+ }
+ }
+
+ /** An iterator whose second next() throws an AssertionError. */
+ public static Iterator<String> failingIterator() {
+ return new Iterator<>() {
+ private int n;
+
+ @Override
+ public boolean hasNext() {
+ return n < 3;
+ }
+
+ @Override
+ public String next() {
+ if (n++ == 1) {
+ throw new AssertionError("iterator failed");
+ }
+ return "part" + n;
+ }
+ };
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/OnPrepareThrowsErrorTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/OnPrepareThrowsErrorTest.java
new file mode 100644
index 000000000000..71ba6ec32567
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/OnPrepareThrowsErrorTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.processor;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * An Error that is not a VirtualMachineError, thrown by the onPrepare
processor of a split, multicast or recipient
+ * list, fails only the part it prepares, as an exception does: the other
parts are still sent.
+ */
+class OnPrepareThrowsErrorTest extends ContextTestSupport {
+
+ @Test
+ void testSplit() throws Exception {
+ assertOnlyThePartFails("direct:split", new AssertionError("Forced"));
+ }
+
+ @Test
+ void testStreamingSplit() throws Exception {
+ assertOnlyThePartFails("direct:streamingSplit", new
AssertionError("Forced"));
+ }
+
+ @Test
+ void testRecipientList() throws Exception {
+ assertOnlyThePartFails("direct:recipientList", new
AssertionError("Forced"));
+ }
+
+ @Test
+ void testSplitWithStopOnException() throws Exception {
+ // the part fails as for an exception: the split stops at it, and
wraps it
+ getMockEndpoint("mock:part").expectedBodiesReceived("a");
+ AssertionError failure = new AssertionError("Forced");
+
+ Exchange out = template.asyncSend("direct:stopOnException", e -> {
+ e.getMessage().setBody("a,b,c");
+ e.setProperty("failure", failure);
+ }).get(10, TimeUnit.SECONDS);
+
+ assertMockEndpointsSatisfied();
+ CamelExchangeException wrapper =
assertInstanceOf(CamelExchangeException.class, out.getException());
+ assertTrue(wrapper.getMessage().startsWith("Multicast processing
failed for number 1"), wrapper.getMessage());
+ assertTrue(causedBy(wrapper, failure), "Expected the AssertionError in
the causes of " + wrapper);
+ assertEquals(0, context.getInflightRepository().size());
+ }
+
+ @Test
+ void testSplitWithAnException() throws Exception {
+ // control: an exception already failed only the part
+ assertOnlyThePartFails("direct:split", new
IllegalArgumentException("Forced"));
+ }
+
+ private void assertOnlyThePartFails(String uri, Throwable failure) throws
Exception {
+ getMockEndpoint("mock:part").expectedBodiesReceived("a", "c");
+
+ Exchange out = template.asyncSend(uri, e -> {
+ e.getMessage().setBody("a,b,c");
+ e.setProperty("failure", failure);
+ }).get(10, TimeUnit.SECONDS);
+
+ assertMockEndpointsSatisfied();
+ // the failed part fails the exchange at the end, as for an exception
+ assertNotNull(out.getException());
+ assertTrue(causedBy(out.getException(), failure), "Expected " +
failure + " in the causes of " + out.getException());
+ assertEquals(0, context.getInflightRepository().size());
+ }
+
+ private static boolean causedBy(Throwable t, Throwable cause) {
+ for (Throwable c = t; c != null; c = c.getCause()) {
+ if (c == cause) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ Processor failing = e -> {
+ if ("b".equals(e.getMessage().getBody(String.class))) {
+ Throwable t = e.getProperty("failure",
Throwable.class);
+ if (t instanceof Error error) {
+ throw error;
+ }
+ throw (RuntimeException) t;
+ }
+ };
+
+
from("direct:split").split(body().tokenize(",")).onPrepare(failing).to("mock:part");
+
from("direct:stopOnException").split(body().tokenize(",")).stopOnException().onPrepare(failing)
+ .to("mock:part");
+
from("direct:streamingSplit").split(body().tokenize(",")).streaming().onPrepare(failing).to("mock:part");
+ from("direct:recipientList")
+
.recipientList(constant("direct:a,direct:b,direct:c")).onPrepare(e -> {
+ // the part sent to direct:b fails
+ String to = e.getProperty(Exchange.TO_ENDPOINT,
String.class);
+
e.getMessage().setBody(to.substring(to.lastIndexOf('/') + 1));
+ failing.process(e);
+ });
+ from("direct:a").to("mock:part");
+ from("direct:b").to("mock:part");
+ from("direct:c").to("mock:part");
+ }
+ };
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/SiblingProcessorsThrowErrorTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/SiblingProcessorsThrowErrorTest.java
index 320ca60aa958..cd5bb717b0d5 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/SiblingProcessorsThrowErrorTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/SiblingProcessorsThrowErrorTest.java
@@ -141,9 +141,9 @@ class SiblingProcessorsThrowErrorTest extends
ContextTestSupport {
@Test
void synchronousSplitFailsTheExchangeWithAnErrorOfItsAggregationStrategy()
throws Exception {
- // the Error leaves the split task (which catches only exceptions)
through the reactive executor and the await
- // manager of the synchronous split, and reaches the catch around the
await manager: the exchange fails instead
- // of continuing after the callback (doDone of the split is skipped on
this path, as before)
+ // the split task fails the exchange with the Error of the
AggregationStrategy (see MulticastTaskThrowsErrorTest
+ // for the other modes); the catch around the await manager of the
synchronous split is still there for an Error
+ // that leaves the task: either way the exchange fails instead of
continuing after the callback
getMockEndpoint("mock:part").expectedBodiesReceived("a");
getMockEndpoint("mock:after").expectedMessageCount(0);
getMockEndpoint("mock:handled").expectedMessageCount(1);
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 08a621a0ae8d..3f1bf1061f29 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
@@ -1202,12 +1202,20 @@ must now check the exception of the returned exchange
(`exchange.getException()`
The same now applies to an `Error` that is not a `VirtualMachineError` thrown
by the expression of a `recipientList`, by
the expression of a `split` with `synchronous=true` (or while a `multicast` or
`recipientList` with `synchronous=true`
-prepares its parts), by the `AggregationStrategy` of a `split`, `multicast` or
`recipientList` with `synchronous=true`
-and without `parallelProcessing`, by a data type transformer (`transform` to a
data type), and by the producer of a
-component built on the API component framework when it is not thrown by an API
method called by reflection (for example
-when the producer creates its client, or calls a client method directly); an
`Error` of an API method called by
-reflection already failed the exchange. Before, depending on the error
handler, the route continued as if the step had
-succeeded, or the `Error` reached the caller (for the producer of an API
component, the `Error` was lost on its thread).
+prepares its parts), by the `AggregationStrategy` of a `split`, `multicast` or
`recipientList` (also when its `timeout`
+is called), by the iterator of a `split` with `streaming()`, by a data type
transformer (`transform` to a data type),
+and by the producer of a component built on the API component framework when
it is not thrown by an API method called
+by reflection (for example when the producer creates its client, or calls a
client method directly); an `Error` of an
+API method called by reflection already failed the exchange. Before, depending
on the error handler, the route
+continued as if the step had succeeded, or the `Error` reached the caller. An
`Error` of the `AggregationStrategy` or
+of the iterator of a streaming `split` (unless the EIP was `synchronous=true`
or the exchange transacted, in both cases
+without `parallelProcessing`) reached the caller without the error handler,
and the exchange stayed inflight until the
+CamelContext stopped; with `parallelProcessing` (or when the timeout was
called) it was lost on a thread of the pool,
+and the caller got no answer. For the producer of an API component, the
`Error` was lost on its thread.
+An `Error` of the `onPrepare` processor of a `split`, `multicast` or
`recipientList` fails only the part it prepares, as
+an exception does, and the other parts are still sent. Before, no part was
sent (for a streaming `split`, no part
+after it). The same applies to an `Error` that a part of a transacted `split`,
`multicast` or `recipientList` (without
+`parallelProcessing`) throws to the EIP: before, the parts after it were not
sent.
There is no option for the old behaviour. See also
xref:error-handler.adoc#_an_error_thrown_by_a_processor[An Error thrown by a
processor].
diff --git a/docs/user-manual/modules/ROOT/pages/error-handler.adoc
b/docs/user-manual/modules/ROOT/pages/error-handler.adoc
index 8d4692f293ac..fe6214b5c3f9 100644
--- a/docs/user-manual/modules/ROOT/pages/error-handler.adoc
+++ b/docs/user-manual/modules/ROOT/pages/error-handler.adoc
@@ -186,10 +186,10 @@ additional documentation of the features above.
A plain `Processor` (in `process(...)`, in `bean(...)` for a bean that is a
`Processor`, or a producer that is not an
`AsyncProcessor`) may throw an `Error` instead of an exception. The same rules
apply to an `Error` of the expression of
-a `recipientList`, of the expression of a `split` with `synchronous=true`, of
the watermark expression of a `split`
-(it fails that item), of the `AggregationStrategy` of a `split`, `multicast`
or `recipientList` with
-`synchronous=true` and without `parallelProcessing`, of the
`AggregationStrategy` of an `enrich` or `pollEnrich`, of a
-data type transformer, of a transformer or validator of the input or output
type of a route (`inputType`,
+a `recipientList`, of the expression of a `split` with `synchronous=true`, of
the watermark expression of a `split` (it
+fails that item), of the `AggregationStrategy` of a `split`, `multicast` or
`recipientList` (also when its `timeout` is
+called), of the iterator of a `split` with `streaming()`, of the
`AggregationStrategy` of an `enrich` or `pollEnrich`,
+of a data type transformer, of a transformer or validator of the input or
output type of a route (`inputType`,
`outputType`), and of a plain `Processor` of a transacted exchange in a step
without an error handler of its own (such
as in a `doTry` block):
@@ -211,7 +211,13 @@ resource is released as failed
|A `VirtualMachineError`, such as `OutOfMemoryError`, `StackOverflowError` or
`InternalError`
|Camel's error handling does not get it (the JVM may no longer be in a
consistent state, so the application should not
handle it). It is not set on the exchange, but thrown on after the processor's
-callback was called. Depending on the error handler, the `Error` reaches the
caller (and the exchange may stay
+callback was called.
+A `VirtualMachineError` of an `AggregationStrategy` or of the iterator of a
split is thrown on from the task of the
+EIP. The callback is then called only when the EIP is `synchronous=true` or
the exchange is transacted, in both cases
+without `parallelProcessing`.
+With `parallelProcessing`, or from the `timeout` of the strategy, the
`VirtualMachineError` is lost on a thread of the
+pool.
+Depending on the error handler, the `Error` reaches the caller (and the
exchange may stay
inflight), or it is only logged and the route continues as if the processor
had succeeded
|===