[
https://issues.apache.org/jira/browse/CAMEL-22950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18055994#comment-18055994
]
Claus Ibsen commented on CAMEL-22950:
-------------------------------------
You are welcome to make the PR with a fix as it should be something like
{code:java}
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ Exchange target = oldExchange != null ? oldExchange : newExchange;
if (propagateException) {
Exception exception = checkException(oldExchange, newExchange);
if (exception != null) {
if (original != null) {
original.setException(exception);
} else {
- oldExchange.setException(exception);
+ target.setException(exception);
}
}
exception = checkCaughtException(oldExchange, newExchange);
@@ -79,7 +80,7 @@ public class UseOriginalAggregationStrategy implements
AggregationStrategy {
}
}
}
- return original != null ? original : oldExchange;
+ return original != null ? original : target;
} {code}
And it would be nice if you can make an unit test, but to be included in
core/camel-core where we have unit tests. Then its not using spring boot, but
pure camel.
> 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.10.8, 4.17.0
> Reporter: Dave Riseley
> Priority: Minor
> Fix For: 4.18.0
>
>
> 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)