You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dm...@apache.org on 2018/07/03 09:21:53 UTC
[camel] branch master updated: CAMEL-12607: When using Tokenizer
skipFirst - java.util.NoSuchElementException if only one element
This is an automated email from the ASF dual-hosted git repository.
dmvolod pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new c69cca4 CAMEL-12607: When using Tokenizer skipFirst - java.util.NoSuchElementException if only one element
c69cca4 is described below
commit c69cca45220182a8b8712705272beae037c07c2d
Author: Dmitry Volodin <dm...@gmail.com>
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 {