[ 
https://issues.apache.org/jira/browse/CAMEL-21376?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Grzegorz Rozanski updated CAMEL-21376:
--------------------------------------
    Description: 
I found a case when NullPointerException occurs in 
UseOriginalAggregationStrategy's aggregate method.
 
I have this route configuration:
{code:java}
.multicast(AggregationStrategies.useOriginal()).parallelProcessing()
.to(DIRECT_ROUTE1)
.to(DIRECT_ROUTE2) 
{code}
 
and in DIRECT_ROUTE2 has this:
{code:java} 
.doTry() 
.unmarshal().zipFile()
{code}

when the zip file is invalid there's exception handling in 
UseOriginalAggregationStrategy::aggregate method:
 
{code:java}
exception = checkCaughtException(oldExchange, newExchange);
if (exception != null) {
    if (original != null) {
        original.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
    } else {
        oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);   //NULL 
POINTER oldExchange is null
    }
} {code}
 
I checked javadoc about this aggregate method it says that:
Params:
oldExchange - the oldest exchange (is null on first aggregation as we only have 
the new exchange)
 
and I think this is what happens in my case when I get NullPointerException in 
line 78 (oldExchange is null):
 
{code:java}
 } else {
      oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
}
 {code}

When I create my own aggregation strategy based on 
UseOriginalAggregationStrategy and modify this `else` part everything works 
properly:
 
{code:java}
} else if (oldExchange != null) {
      oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
}
{code}
 
I see that similar null check already exists in checkCaughtException method.
 
 The full stack trace can be found as attachment to this ticket.

  was:
I found a case when NullPointerException occurs in 
UseOriginalAggregationStrategy's aggregate method.
 
I have this route configuration:
{code:java}
.multicast(AggregationStrategies.useOriginal()).parallelProcessing()
.to(DIRECT_ROUTE1)
.to(DIRECT_ROUTE2) 
{code}
 
and in DIRECT_ROUTE2 has this:
{code:java} 
.doTry() 
.unmarshal().zipFile()
{code}

when the zip file is invalid there's exception handling in 
UseOriginalAggregationStrategy::aggregate method:
 
{code:java}
exception = checkCaughtException(oldExchange, newExchange);
if (exception != null) {
    if (original != null) {
        original.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
    } else {
        oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);   //NULL 
POINTER oldExchange is null
    }
} {code}
 
I checked javadoc about this aggregate method it says that:
Params:
oldExchange - the oldest exchange (is null on first aggregation as we only have 
the new exchange)
 
and I think this is what happens in my case when I get NullPointerException in 
line 78 (oldExchange is null):
 
{code:java}
 } else {
      oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
}
 {code}

When I create my own aggregation strategy based on 
UseOriginalAggregationStrategy and modify this `else` part everything works 
properly:
 
{code:java}
} else if (oldExchange != null) {
      oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
}
{code}
 
I see that similar null check already exists in checkCaughtException method.
 
 The full stack trace can be found as attachment to this ticket.


> UseOriginalAggregationStrategy - null pointer
> ---------------------------------------------
>
>                 Key: CAMEL-21376
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21376
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core
>    Affects Versions: 4.8.0
>            Reporter: Grzegorz Rozanski
>            Priority: Minor
>             Fix For: 4.8.2, 4.9.0
>
>         Attachments: camel-null-pointer.log
>
>
> I found a case when NullPointerException occurs in 
> UseOriginalAggregationStrategy's aggregate method.
>  
> I have this route configuration:
> {code:java}
> .multicast(AggregationStrategies.useOriginal()).parallelProcessing()
> .to(DIRECT_ROUTE1)
> .to(DIRECT_ROUTE2) 
> {code}
>  
> and in DIRECT_ROUTE2 has this:
> {code:java} 
> .doTry() 
> .unmarshal().zipFile()
> {code}
> when the zip file is invalid there's exception handling in 
> UseOriginalAggregationStrategy::aggregate method:
>  
> {code:java}
> exception = checkCaughtException(oldExchange, newExchange);
> if (exception != null) {
>     if (original != null) {
>         original.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
>     } else {
>         oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);   
> //NULL POINTER oldExchange is null
>     }
> } {code}
>  
> I checked javadoc about this aggregate method it says that:
> Params:
> oldExchange - the oldest exchange (is null on first aggregation as we only 
> have the new exchange)
>  
> and I think this is what happens in my case when I get NullPointerException 
> in line 78 (oldExchange is null):
>  
> {code:java}
>  } else {
>       oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
> }
>  {code}
> When I create my own aggregation strategy based on 
> UseOriginalAggregationStrategy and modify this `else` part everything works 
> properly:
>  
> {code:java}
> } else if (oldExchange != null) {
>       oldExchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
> }
> {code}
>  
> I see that similar null check already exists in checkCaughtException method.
>  
>  The full stack trace can be found as attachment to this ticket.



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

Reply via email to