Dave Riseley created CAMEL-22950:
------------------------------------

             Summary: UseOriginalAggregationStrategy fails to capture exception 
with NPE
                 Key: CAMEL-22950
                 URL: https://issues.apache.org/jira/browse/CAMEL-22950
             Project: Camel
          Issue Type: Bug
          Components: came-core
    Affects Versions: 4.17.0, 4.10.8
            Reporter: Dave Riseley


Similar to CAMEL-21376, UseOriginalAggregationStrategy  fails to capture an 
exception with an NPE if the oldExchange is null (the first message in an 
aggregation).

The exception is as follows:
{code:java}
java.lang.NullPointerException: Cannot invoke 
"org.apache.camel.Exchange.setException(java.lang.Throwable)" because 
"oldExchange" is null
        at 
org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy.aggregate(UseOriginalAggregationStrategy.java:70)
        at 
org.apache.camel.AggregationStrategy.aggregate(AggregationStrategy.java:86)
        at 
org.apache.camel.processor.MulticastProcessor.doAggregateInternal(MulticastProcessor.java:944)
        at 
org.apache.camel.processor.MulticastProcessor.doAggregateSync(MulticastProcessor.java:922)
        at 
org.apache.camel.processor.MulticastProcessor.doAggregate(MulticastProcessor.java:905)
        at 
org.apache.camel.processor.MulticastProcessor$MulticastTask.aggregate(MulticastProcessor.java:462)
        at 
org.apache.camel.processor.MulticastProcessor$MulticastReactiveTask.lambda$run$0(MulticastProcessor.java:605)
...
{code}
The relevant bit of code appears to be this:
{code:java}
            if (exception != null) {
                if (original != null) {
                    original.setException(exception);
                } else {
==>                 oldExchange.setException(exception);
                }
            }
{code}
A camel route that would reproduce this issue is as follows:
{code:java}
from(direct("reproducer"))
            .errorHandler(noErrorHandler())
            .recipientList(constant(
                "direct:reproducer1," +
                "direct:reproducer2"))
            .aggregationStrategy(AggregationStrategies.useOriginal());

from(direct("reproducer1"))
            .log("reproducer1")
            .process(exchange -> {throw new RuntimeException("reproducer1");});
from(direct("reproducer2"))
            .log("reproducer2");
{code}
A reproducer project has been provided here (by my colleague Ferenc): 
[https://github.com/FerencKissJs/use-original-aggregation-strategy-null-pointer-exception]
Pulling the project and running "mvn clean test" should show the bug being 
triggered

Happy to provide a PR if needed, but not sure what the correct fix should be as 
simply adding a null check would cause the exception to be lost?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to