From 6e6d8605d359316c5d527952408e412e29973531 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 6 Sep 2011 19:35:33 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3467 Handle a potential NPE case. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1165797 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/kahadb/util/SequenceSet.java | 6 ++++-- .../java/org/apache/kahadb/util/SequenceSetTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java b/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java index 87411b1380..a3bdeae925 100644 --- a/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java +++ b/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java @@ -369,11 +369,13 @@ public class SequenceSet extends LinkedNodeList implements Iterable { private Sequence currentEntry; - private long lastReturned; + private long lastReturned = -1; public SequenceIterator() { currentEntry = getHead(); - lastReturned = currentEntry.first - 1; + if (currentEntry != null) { + lastReturned = currentEntry.first - 1; + } } public boolean hasNext() { diff --git a/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java b/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java index ebc8043f4c..48c9e484f5 100644 --- a/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java +++ b/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java @@ -126,4 +126,14 @@ public class SequenceSetTest { assertEquals(expected[index++], iterator.next().longValue()); } } + + @Test + public void testIteratorEmptySequenceSet() { + SequenceSet set = new SequenceSet(); + + Iterator iterator = set.iterator(); + while(iterator.hasNext()) { + fail("Should not have any elements"); + } + } }