From 40d91908fbbb99e4c18c943b3b3b022cc63fe08f Mon Sep 17 00:00:00 2001 From: velocipedist Date: Tue, 12 Nov 2013 12:35:41 +0000 Subject: [PATCH] Updated next() method to satisfy the iterator contract and not throw a null pointer exception, if it was called without hasNext() being called. The previous implementation did not initialize the *currentSegmentIterator*, unless *hasNext()* has been called, which lead to unexpected *NullPointerException*. I've changed the impl to call *hasNext()* prior to the next call. --- .../storage/utils/implementation/LazySegmentedIterator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/LazySegmentedIterator.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/LazySegmentedIterator.java index f43f0a41b8d5..86c3a1529fe3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/LazySegmentedIterator.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/LazySegmentedIterator.java @@ -130,7 +130,11 @@ public boolean hasNext() { */ @Override public ENTITY_TYPE next() { - return this.currentSegmentIterator.next(); + if(hasNext()) { + return this.currentSegmentIterator.next(); + } else { + throw new NoSuchElementException(); + } } /**