title: Mule scatter-gather router throwing exception
body: <p>I was exploring Mule scatter-gather for parallel processing of flows in Mule <strong>fork and join</strong> pattern. My Mule config is as follows:</p>
  
  <pre><code> &lt;flow name="fork" doc:name="fork"&gt;
      &lt;http:inbound-endpoint host="localhost" port="8090" path="mainPath" exchange-pattern="request-response" doc:name="HTTP"/&gt;
      &lt;set-property propertyName="MULE_CORRELATION_GROUP_SIZE"  value="2" doc:name="Property"/&gt;
       &lt;!--  &lt;all enableCorrelation="IF_NOT_SET" doc:name="All"&gt; --&gt;
              &lt;scatter-gather timeout="6000"&gt;
                &lt;processor-chain&gt;
                 &lt;async doc:name="Async"&gt;
                 &lt;set-property propertyName="MULE_CORRELATION_SEQUENCE" value="1" doc:name="Property"/&gt;
                 &lt;flow-ref name="Flow1" doc:name="Flow Reference"/&gt;
                 &lt;/async&gt;
                &lt;/processor-chain&gt;
  
                &lt;async doc:name="Async"&gt;
                &lt;set-property propertyName="MULE_CORRELATION_SEQUENCE" value="2" doc:name="Property"/&gt;
                &lt;flow-ref name="Flow2" doc:name="Flow Reference"/&gt;
                 &lt;/async&gt;
                 &lt;!-- &lt;/all&gt; --&gt;
                 &lt;/scatter-gather&gt;
                 &lt;logger message="Main Flow" level="INFO" doc:name="Logger"/&gt;
      &lt;/flow&gt;
  
      &lt;sub-flow name="Flow1" doc:name="Flow1"&gt;
       &lt;logger level="INFO" message="Flow1: processing started" doc:name="Logger"/&gt;
       &lt;set-payload value="Flow1 Payload" doc:name="Set Payload"/&gt;
       &lt;!-- Transformation payload --&gt;
        &lt;logger level="INFO" message="Flow1: processing finished" doc:name="Logger"/&gt;
        &lt;flow-ref name="Join-Flow" doc:name="Flow Reference"/&gt;
       &lt;/sub-flow&gt;
  
      &lt;sub-flow name="Flow2" doc:name="Flow2"&gt;
      &lt;logger level="INFO" message="Flow2: processing started" doc:name="Logger"/&gt;
       &lt;set-payload value="Flow2 Payload" doc:name="Set Payload"/&gt;
       &lt;scripting:component doc:name="Groovy"&gt;
       &lt;scripting:script engine="Groovy"&gt;&lt;![CDATA[sleep(2000); return message.payload;]]&gt;&lt;/scripting:script&gt;
       &lt;/scripting:component&gt;
        &lt;!--  Transformation payload --&gt;
      &lt;logger level="INFO" message="Flow2: processing finished" doc:name="Logger"/&gt;
       &lt;flow-ref name="Join-Flow" doc:name="Flow Reference"/&gt;
      &lt;/sub-flow&gt;
  
      &lt;sub-flow name="Join-Flow" doc:name="Join-Flow"&gt;
      &lt;collection-aggregator timeout="6000" failOnTimeout="true" doc:name="Collection Aggregator"/&gt;
      &lt;combine-collections-transformer doc:name="Combine Collections"/&gt;
      &lt;logger level="INFO"  message="Combined Payload: #[message.payload]" doc:name="Logger"/&gt;
      &lt;set-payload value="Soap XML Response" doc:name="Set Payload"/&gt;
      &lt;/sub-flow&gt; 
  </code></pre>
  
  <p>The scatter and gather is throwing following exception though I am getting the aggregated Payload in Logger:</p>
  
  <pre><code>Exception stack is:
  1. null (java.lang.UnsupportedOperationException)
    org.mule.VoidMuleEvent:50 (null)
  2. null (java.lang.UnsupportedOperationException). Message payload is of type: String (org.mule.api.MessagingException)
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  java.lang.UnsupportedOperationException
      at org.mule.VoidMuleEvent.getMessage(VoidMuleEvent.java:50)
      at org.mule.api.routing.AggregationContext$1.evaluate(AggregationContext.java:41)
      at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:517)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  
  INFO  2014-08-17 18:04:52,008 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing started
  INFO  2014-08-17 18:04:52,016 [[try1].fork.1.02] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing started
  INFO  2014-08-17 18:04:52,017 [[try1].fork.1.02] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing finished
  INFO  2014-08-17 18:04:54,309 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing finished
  INFO  2014-08-17 18:04:54,347 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Combined Payload: [Flow1 Payload, Flow2 Payload]
  </code></pre>
  
  <p>One interesting fact is that if I use <code>&lt;all&gt;</code> router instead of scatter-gather, I don't get this exception. but I guess <code>&lt;all&gt;</code> router process the flows sequentially and not in parallel as per <a href="http://www.mulesoft.org/documentation/display/current/Scatter-Gather" rel="nofollow">Mule documentation</a>. So for that reason I tried to choose <strong>scatter-gather</strong> over <strong>all</strong> router. But I am not sure how to handle the above exception thrown by the <strong>scatter-gather</strong>. Is there any way out?</p>
  
  <p><strong>UPDATED FLOW :-</strong> </p>
  
  <pre><code>&lt;flow name="fork" doc:name="fork"&gt;
  &lt;http:inbound-endpoint host="localhost" port="8090" path="mainPath" exchange-pattern="request-response" doc:name="HTTP"/&gt;
  
  
           &lt;scatter-gather timeout="6000"&gt;
              &lt;processor-chain&gt;
                &lt;flow-ref name="Flow1" doc:name="Flow Reference"/&gt;
                   &lt;/processor-chain&gt;
                 &lt;flow-ref name="Flow2" doc:name="Flow Reference"/&gt;
            &lt;/scatter-gather&gt;
              &lt;logger message="Main Flow" level="INFO" doc:name="Logger"/&gt;
          &lt;/flow&gt;
  
          &lt;sub-flow name="Flow1" doc:name="Flow1"&gt;
           &lt;logger level="INFO" message="Flow1: processing started" doc:name="Logger"/&gt;
           &lt;set-payload value="Flow1 Payload" doc:name="Set Payload"/&gt;
           &lt;!-- Transformation payload --&gt;
            &lt;logger level="INFO" message="Flow1: processing finished" doc:name="Logger"/&gt;
            &lt;flow-ref name="Join-Flow" doc:name="Flow Reference"/&gt;
           &lt;/sub-flow&gt;
  
          &lt;sub-flow name="Flow2" doc:name="Flow2"&gt;
          &lt;logger level="INFO" message="Flow2: processing started" doc:name="Logger"/&gt;
           &lt;set-payload value="Flow2 Payload" doc:name="Set Payload"/&gt;
           &lt;scripting:component doc:name="Groovy"&gt;
           &lt;scripting:script engine="Groovy"&gt;&lt;![CDATA[sleep(2000); return message.payload;]]&gt;    
           &lt;/scripting:script&gt;
           &lt;/scripting:component&gt;
            &lt;!--  Transformation payload --&gt;
          &lt;logger level="INFO" message="Flow2: processing finished" doc:name="Logger"/&gt;
           &lt;flow-ref name="Join-Flow" doc:name="Flow Reference"/&gt;
          &lt;/sub-flow&gt;
  
          &lt;sub-flow name="Join-Flow" doc:name="Join-Flow"&gt;
          &lt;collection-aggregator timeout="6000" failOnTimeout="true" doc:name="Collection Aggregator"/&gt;
          &lt;combine-collections-transformer doc:name="Combine Collections"/&gt;
          &lt;logger level="INFO"  message="Combined Payload: #[message.payload]" doc:name="Logger"/&gt;
          &lt;set-payload value="Soap XML Response" doc:name="Set Payload"/&gt;
          &lt;/sub-flow&gt; 
  </code></pre>
  
  <p><strong>EXCEPTION :-</strong></p>
  
  <pre><code>[try1].ScatterGatherWorkManager.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing started
  INFO  2014-08-18 13:34:24,361 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing started
  INFO  2014-08-18 13:34:24,364 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing finished
  WARN  2014-08-18 13:34:24,366 [[try1].ScatterGatherWorkManager.01] org.mule.routing.correlation.CollectionCorrelatorCallback: Correlation Group Size not set, but correlation aggregator is being used. Message is being forwarded as is
  INFO  2014-08-18 13:34:24,401 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Combined Payload: [Flow1 Payload]
  INFO  2014-08-18 13:34:26,615 [[try1].ScatterGatherWorkManager.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing finished
  ERROR 2014-08-18 13:34:26,625 [[try1].connector.http.mule.default.receiver.03] org.mule.exception.DefaultMessagingExceptionStrategy: 
  ********************************************************************************
  Message               : null (java.lang.NullPointerException). Message payload is of type: String
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
  1. null (java.lang.NullPointerException)
    org.mule.api.routing.AggregationContext$1:41 (null)
  2. null (java.lang.NullPointerException). Message payload is of type: String (org.mule.api.MessagingException)
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  java.lang.NullPointerException
      at org.mule.api.routing.AggregationContext$1.evaluate(AggregationContext.java:41)
      at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:517)
      at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:498)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  </code></pre>
  
  <p>Now as you can see it's not combining the both payload of both flow after removing the set-property ..... It is getting only payload of first flow :- Combined Payload: <code>[Flow1 Payload]</code> ..</p>