From 4f3da9a89a0f0a96a8b45094785b40cfeef5ade9 Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Wed, 13 Nov 2019 17:58:36 +0000 Subject: [PATCH] PDFBOX-4687: Iterator.next() methods should throw NoSuchElementException, as suggested by SonarCloud and Haris Adzemovic; closes #75 git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1869762 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java | 5 +++++ .../documentnavigation/outline/PDOutlineItemIterator.java | 5 +++++ 2 files changed, 10 insertions(+) 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;