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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 7fd53e9f Fix SpotBugs error: 
org.apache.commons.io.function.IOStream$1.next() cannot throw 
NoSuchElementException [org.apache.commons.io.function.IOStream$1] At 
IOStream.java:[line 98] IT_NO_SUCH_ELEMENT
7fd53e9f is described below

commit 7fd53e9f0a8b2ce09a1a5f364e8838c74e292b7c
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Nov 23 11:33:22 2023 -0500

    Fix SpotBugs error: org.apache.commons.io.function.IOStream$1.next()
    cannot throw NoSuchElementException
    [org.apache.commons.io.function.IOStream$1] At IOStream.java:[line 98]
    IT_NO_SUCH_ELEMENT
---
 src/changes/changes.xml                                       |  1 +
 src/main/java/org/apache/commons/io/function/IOStream.java    | 11 +++++++++--
 .../java/org/apache/commons/io/function/IOStreamTest.java     |  3 ++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c46bb862..6518d1dc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -58,6 +58,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs 
error: Class org.apache.commons.io.filefilter.RegexFileFilter defines 
non-transient non-serializable instance field pathToString 
[org.apache.commons.io.filefilter.RegexFileFilter] In RegexFileFilter.java 
SE_BAD_FIELD.</action>
       <action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs 
error: Class org.apache.commons.io.filefilter.DelegateFileFilter defines 
non-transient non-serializable instance field fileFilter 
[org.apache.commons.io.filefilter.DelegateFileFilter] In 
DelegateFileFilter.java SE_BAD_FIELD.</action>
       <action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs 
error: Class org.apache.commons.io.filefilter.DelegateFileFilter defines 
non-transient non-serializable instance field fileNameFilter 
[org.apache.commons.io.filefilter.DelegateFileFilter] In 
DelegateFileFilter.java SE_BAD_FIELD.</action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs 
error: org.apache.commons.io.function.IOStream$1.next() cannot throw 
NoSuchElementException [org.apache.commons.io.function.IOStream$1] At 
IOStream.java:[line 98] IT_NO_SUCH_ELEMENT.</action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update" due-to="Gary Gregory">Bump 
org.codehaus.mojo:exec-maven-plugin from 3.1.0 to 3.1.1 #512.</action>
       <action dev="ggregory" type="update" due-to="Gary Gregory">Bump 
commons-lang3 from 3.13.0 to 3.14.0.</action>      
diff --git a/src/main/java/org/apache/commons/io/function/IOStream.java 
b/src/main/java/org/apache/commons/io/function/IOStream.java
index 5e78e6c9..3eac5bfb 100644
--- a/src/main/java/org/apache/commons/io/function/IOStream.java
+++ b/src/main/java/org/apache/commons/io/function/IOStream.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Spliterator;
@@ -93,8 +94,14 @@ public interface IOStream<T> extends IOBaseStream<T, 
IOStream<T>, Stream<T>> {
             }
 
             @Override
-            public T next() {
-                return t = t == IOStreams.NONE ? seed : Erase.apply(f, t);
+            public T next() throws NoSuchElementException {
+                try {
+                    return t = t == IOStreams.NONE ? seed : f.apply(t);
+                } catch (IOException e) {
+                    final NoSuchElementException nsee = new 
NoSuchElementException();
+                    nsee.initCause(e);
+                    throw nsee;
+                }
             }
         };
         return 
adapt(StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 
Spliterator.ORDERED | Spliterator.IMMUTABLE), false));
diff --git a/src/test/java/org/apache/commons/io/function/IOStreamTest.java 
b/src/test/java/org/apache/commons/io/function/IOStreamTest.java
index 3e2ef9c5..08f7e445 100644
--- a/src/test/java/org/apache/commons/io/function/IOStreamTest.java
+++ b/src/test/java/org/apache/commons/io/function/IOStreamTest.java
@@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.NoSuchElementException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -296,7 +297,7 @@ public class IOStreamTest {
         final IOStream<Long> stream = IOStream.iterate(1L, 
TestUtils.throwingIOUnaryOperator());
         final IOIterator<Long> iterator = stream.iterator();
         assertEquals(1L, iterator.next());
-        assertThrows(IOException.class, () -> iterator.next());
+        assertThrows(NoSuchElementException.class, () -> iterator.next());
     }
 
     @SuppressWarnings("resource") // custom stream not recognized by compiler 
warning machinery

Reply via email to