diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml
index 711b34b0cc6f..ae10d1045dfe 100644
--- a/spotbugs-exclude.xml
+++ b/spotbugs-exclude.xml
@@ -77,9 +77,6 @@
-
-
-
diff --git a/src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java b/src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java
index 8a788317c372..171f24e09396 100644
--- a/src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java
+++ b/src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java
@@ -148,8 +148,11 @@ public boolean hasNext() {
@Override
public T next() {
- node = node.next;
- return node.data;
+ if (hasNext()) {
+ node = node.next;
+ return node.data;
+ }
+ throw new NoSuchElementException();
}
};
}