title: Apache camel aggregate gives exception
body: <p>Regarding the question: <a href="https://stackoverflow.com/questions/34611301/apache-camel-returns-multiple-exceptions-during-a-route">Apache camel returns multiple exceptions during a route</a></p>
  
  <p>Its indicated that I can't get list of strings with split method so I have tried the aggregate method as follows:</p>
  
  <pre><code>public class lowestRates implements AggregationStrategy {
  public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
      String oldStr = oldExchange.getIn().getBody(String.class);
      String newStr = newExchange.getIn().getBody(String.class);
      Pattern p = Pattern.compile("(\\w+)\\s(\\d+)");
      Matcher m1 = p.matcher(oldStr);
      Matcher m2 = p.matcher(newStr);
      String finalStr = "";
      if(m1.group(2).equalsIgnoreCase(m2.group(2)))
          finalStr = m1.group(1) + Integer.toString(Integer.parseInt(m1.group(2)) &gt; Integer.parseInt(m2.group(2)) ? Integer.parseInt(m2.group(2)) : Integer.parseInt(m1.group(2)));
      else
          finalStr = oldStr + "\n" + newStr;
      oldExchange.getIn().setBody(finalStr);
      return oldExchange;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and the new main code:</p>
  
  <pre><code>from("file://files")
                      .split()
                      .tokenize("\n")
                      .aggregate(new lowestRates())
                      .body()
                      .completionTimeout(5000)
                      .to("file://files/result.txt")
  </code></pre>
  
  <p>but it gives me:</p>
  
  <pre><code>org.apache.camel.CamelExchangeException: Error occurred during aggregation. Exchange[][Message: Good1 450]. Caused by: [java.lang.NullPointerException - null]
  </code></pre>
  
  <p>Now the question is how to write the correct aggregation method cause I fail to see anything done wrong here :(.</p>