This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.22.x by this push:
     new c2f00e0  CAMEL-12607: When using Tokenizer skipFirst - 
java.util.NoSuchElementException if only one element
c2f00e0 is described below

commit c2f00e0cb868886a301507263e2f4450f237138c
Author: Dmitry Volodin <[email protected]>
AuthorDate: Fri Jun 29 19:43:12 2018 +0300

    CAMEL-12607: When using Tokenizer skipFirst -
    java.util.NoSuchElementException if only one element
---
 .../src/main/java/org/apache/camel/util/GroupTokenIterator.java  | 9 +++++++--
 .../java/org/apache/camel/processor/SplitGroupSkipFirstTest.java | 8 ++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/camel-core/src/main/java/org/apache/camel/util/GroupTokenIterator.java 
b/camel-core/src/main/java/org/apache/camel/util/GroupTokenIterator.java
index 0bfd268..2f05116 100644
--- a/camel-core/src/main/java/org/apache/camel/util/GroupTokenIterator.java
+++ b/camel-core/src/main/java/org/apache/camel/util/GroupTokenIterator.java
@@ -50,7 +50,7 @@ public final class GroupTokenIterator implements 
Iterator<Object>, Closeable {
     private final ByteArrayOutputStream bos = new ByteArrayOutputStream();
     
     /**
-     * Creates a new token based group titerator
+     * Creates a new token based group iterator
      *
      * @param camelContext  the camel context
      * @param it            the iterator to group
@@ -155,7 +155,12 @@ public final class GroupTokenIterator implements 
Iterator<Object>, Closeable {
             data = it.next();
 
             if (skipFirst && hasSkipFirst.compareAndSet(false, true)) {
-                data = it.next();
+                if (it.hasNext()) {
+                    data = it.next();
+                } else {
+                    // Content with header only which is marked to skip
+                    data = "";
+                }
             }
 
             // include token in between
diff --git 
a/camel-core/src/test/java/org/apache/camel/processor/SplitGroupSkipFirstTest.java
 
b/camel-core/src/test/java/org/apache/camel/processor/SplitGroupSkipFirstTest.java
index d85cac2..5c09847 100644
--- 
a/camel-core/src/test/java/org/apache/camel/processor/SplitGroupSkipFirstTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/processor/SplitGroupSkipFirstTest.java
@@ -31,6 +31,14 @@ public class SplitGroupSkipFirstTest extends 
ContextTestSupport {
 
         assertMockEndpointsSatisfied();
     }
+    
+    public void testSplitSkipFirstOnlyHeader() throws Exception {
+        getMockEndpoint("mock:group").expectedBodiesReceived("");
+
+        template.sendBody("direct:start", "##comment\n");
+
+        assertMockEndpointsSatisfied();
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {

Reply via email to