You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/04/22 12:59:43 UTC

[groovy] 01/02: fix spotbugs warning (throw NoSuchElementException rather than ArrayIndexOutOfBoundsException when accessing exhausted iterator)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ec68924d6de100f3d2d1916fec1d7dbe24f89d87
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Apr 22 22:59:08 2020 +1000

    fix spotbugs warning (throw NoSuchElementException rather than ArrayIndexOutOfBoundsException when accessing exhausted iterator)
---
 src/main/java/org/codehaus/groovy/util/ArrayIterator.java | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/util/ArrayIterator.java b/src/main/java/org/codehaus/groovy/util/ArrayIterator.java
index 53b1d92..27bc880 100644
--- a/src/main/java/org/codehaus/groovy/util/ArrayIterator.java
+++ b/src/main/java/org/codehaus/groovy/util/ArrayIterator.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.util;
 
 import java.lang.reflect.Array;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 public class ArrayIterator<T> implements Iterator<T> {
     private final T[] array;
@@ -37,6 +38,9 @@ public class ArrayIterator<T> implements Iterator<T> {
 
     @SuppressWarnings("unchecked")
     public T next() {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
         return (T) Array.get(array, index++);
     }