Hi, The JUnit test below illustrates a Stack Overflow bug when using a long recipient list with the default delimiter (a comma).
The overflow is caused by a regex (",(?!(?:[^\\(,]|[^\\)],[^\\)])+\\))") in the 'createIterator()' method in the class 'org.apache.camel.util.ObjectHelper', which is used to iterate a recipient list while handling bean expressions with OGNL. The problem is that this complex regex is used *by default* with recipient lists, and if that list is long, it will stack overflow. Thankfully the work-around we use is trivial - we simply use ", " as the delimiter (note the space), and this bypasses using the regex and so everything works fine (illustrated in the Junit test too) - but ultimately I think the regex needs to be re-worked to not overflow on long lists. Here's the simple failing JUnit test: import junit.framework.Assert; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.DefaultExchange; import org.junit.Test; public class LongRecipientListTest { static int recipientCount = 0; /** * */ @Test public void stackOverflowWithLongRecipientListAndDefaultDelimiter() throws Exception { DefaultCamelContext camelContext = new DefaultCamelContext(); StringBuilder buffer = new StringBuilder("direct://long-uri/"); for (int i=0; i < 100; i++) { buffer.append("123456789/"); } final String longUri = buffer.toString(); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct://defaultDelimiter") .recipientList(header("X-Test")).parallelProcessing(); from("direct://customDelimiter") .recipientList(header("X-Test")).parallelProcessing() .delimiter(", "); from(longUri).process(new Processor() { @Override public void process(Exchange exchange) throws Exception { recipientCount++; } }); } }); camelContext.start(); int sendCount = 100; StringBuilder buffer2 = new StringBuilder(longUri); for (int i=0; i < (sendCount - 1); i++) { buffer2.append(", ").append(longUri); } final DefaultExchange exchange = new DefaultExchange(camelContext); exchange.getIn().setHeader("X-Test", buffer2.toString()); recipientCount = 0; camelContext.createProducerTemplate().send("direct://customDelimiter", exchange); *Assert.assertEquals(sendCount, recipientCount); // PASSES* recipientCount = 0; camelContext.createProducerTemplate().send("direct://defaultDelimiter", exchange); *Assert.assertEquals(sendCount, recipientCount); // FAILS!* } } -- View this message in context: http://camel.465427.n5.nabble.com/BUG-Stack-Overflow-with-long-recipient-list-using-default-delimiter-tp5745679.html Sent from the Camel - Users mailing list archive at Nabble.com.