IOExceptionList implements Iterable.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -442,6 +442,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add TimestampedObserver.isClosed().
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ IOExceptionList implements Iterable.
+ </action>
<!-- UPDATE -->
<action dev="kinow" type="update" due-to="Dependabot, Gary Gregory">
Bump actions/cache from 2.1.6 to 3.0.8 #307, #337.

MODIFY
src/main/java/org/apache/commons/io/IOExceptionList.java
src/main/java/org/apache/commons/io/IOExceptionList.java
import java.io.IOException;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Objects;
*
* @since 2.7
*/
-public class IOExceptionList extends IOException {
+public class IOExceptionList extends IOException implements Iterable<Throwable> {
private static final long serialVersionUID = 1L;
@@ -124,4 +125,9 @@ public IOExceptionList(final String message, final List<? extends Throwable> cau
return (List<T>) causeList;
}
+ @Override
+ public Iterator<Throwable> iterator() {
+ return getCauseList().iterator();
+ }
+
}

MODIFY
src/test/java/org/apache/commons/io/IOExceptionListTest.java
src/test/java/org/apache/commons/io/IOExceptionListTest.java
import java.io.EOFException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -67,6 +68,22 @@ public void testEmptyList() {
new IOExceptionList("foo", Collections.emptyList());
}
+ @Test
+ public void testIterable() {
+ final EOFException cause = new EOFException();
+ final List<EOFException> list = Collections.singletonList(cause);
+ final IOExceptionList sqlExceptionList = new IOExceptionList("Hello", list);
+ //
+ assertEquals(list, sqlExceptionList.getCauseList());
+ // No CCE:
+ final List<EOFException> causeList = sqlExceptionList.getCauseList();
+ assertEquals(list, causeList);
+ //
+ final List<Throwable> list2 = new ArrayList<>();
+ sqlExceptionList.forEach(list2::add);
+ assertEquals(list2, causeList);
+ }
+
@Test
public void testMessageCause() {
final EOFException cause = new EOFException();

IOExceptionList implements Iterable.