Federico Mariani created CAMEL-24140:
----------------------------------------

             Summary: camel-core - UseOriginalAggregationStrategy still not 
honored when shareUnitOfWork is enabled (Multicast/Split/RecipientList)
                 Key: CAMEL-24140
                 URL: https://issues.apache.org/jira/browse/CAMEL-24140
             Project: Camel
          Issue Type: Bug
          Components: camel-core, eip
    Affects Versions: 4.21.0, 4.22.0
            Reporter: Federico Mariani


CAMEL-24062 moved the {{UseOriginalAggregationStrategy}} binding into 
{{MulticastProcessor.process()}}:

{code:java}
if (strategy instanceof UseOriginalAggregationStrategy original) {
    AggregationStrategy clone = original.newInstance(exchange);
    if (isShareUnitOfWork()) {
        clone = new ShareUnitOfWorkAggregationStrategy(clone);
    }
    setAggregationStrategyOnExchange(exchange, clone);
}
{code}

However, when {{shareUnitOfWork=true}} the reifiers 
({{MulticastReifier.createAggregationStrategy}}, same in Split/RecipientList 
reifiers) have *already wrapped* the configured strategy in 
{{ShareUnitOfWorkAggregationStrategy}} at route-build time. So 
{{getAggregationStrategy()}} returns the wrapper, the {{instanceof}} never 
matches, and the strategy is never bound to the original exchange — the exact 
"silently ineffective" problem CAMEL-24062 set out to fix. (The inner 
{{isShareUnitOfWork()}} re-wrap in the processor shows the code expects an 
unwrapped strategy at that point.)

In the error scenario described in CAMEL-24062: a branch fails → the unbound 
{{UseOriginalAggregationStrategy}} returns the failed *branch copy* → 
{{doDone}} copies its results onto the original → the original body is replaced 
by the branch's partial body.

This affects Multicast, Splitter and RecipientList alike (for 
Splitter/RecipientList it is the same pre-existing gap, since the code moved by 
CAMEL-24062 was identical — so 4.21.0 and earlier are affected in those EIPs 
too).

*Reproducer (attached, fails on main):* 
{{MulticastUseOriginalShareUnitOfWorkIssueTest}} — identical routes with and 
without {{shareUnitOfWork()}}, branch B sets body "B" then throws. Without 
shareUnitOfWork the body stays {{original}} (CAMEL-24062 fix works); with it 
the failed branch body wins:

{noformat}
org.opentest4j.AssertionFailedError: expected: <original> but was: <B>
{noformat}

Suggested fix direction: unwrap in the check ({{strategy instanceof 
ShareUnitOfWorkAggregationStrategy share && share.getDelegate() instanceof 
UseOriginalAggregationStrategy}}), or stop pre-wrapping in the reifiers and let 
the processor do the wrapping (it already does for the per-exchange clone).

_Filed by Claude Code on behalf of Federico Mariani (fmariani)_



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

Reply via email to