Handle a potential NPE case.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1165797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-09-06 19:35:33 +00:00
parent 82e3be347c
commit 6e6d8605d3
2 changed files with 14 additions and 2 deletions

View File

@ -369,12 +369,14 @@ public class SequenceSet extends LinkedNodeList<Sequence> implements Iterable<Lo
private class SequenceIterator implements Iterator<Long> {
private Sequence currentEntry;
private long lastReturned;
private long lastReturned = -1;
public SequenceIterator() {
currentEntry = getHead();
if (currentEntry != null) {
lastReturned = currentEntry.first - 1;
}
}
public boolean hasNext() {
return currentEntry != null;

View File

@ -126,4 +126,14 @@ public class SequenceSetTest {
assertEquals(expected[index++], iterator.next().longValue());
}
}
@Test
public void testIteratorEmptySequenceSet() {
SequenceSet set = new SequenceSet();
Iterator<Long> iterator = set.iterator();
while(iterator.hasNext()) {
fail("Should not have any elements");
}
}
}