diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java index 3fff155e00a..b8e805c4144 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.NoSuchElementException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -200,6 +201,10 @@ public boolean hasNext() @Override public PDPage next() { + if (!hasNext()) + { + throw new NoSuchElementException(); + } COSDictionary next = queue.poll(); sanitizeType(next); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItemIterator.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItemIterator.java index 5c7675af5ea..984c09ca556 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItemIterator.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItemIterator.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline; import java.util.Iterator; +import java.util.NoSuchElementException; /** * Iterator over the linked list of {@link PDOutlineItem} siblings. @@ -45,6 +46,10 @@ public boolean hasNext() @Override public PDOutlineItem next() { + if (!hasNext()) + { + throw new NoSuchElementException(); + } if (currentItem == null) { currentItem = startingItem;