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 35d7843  Fix IndexOutOfBoundsException in IOExceptionList contructors.
35d7843 is described below

commit 35d78434cbbc206a0ccede1566a33cd8dd3c7bd1
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jul 6 11:29:24 2021 -0400

    Fix IndexOutOfBoundsException in IOExceptionList contructors.
---
 src/main/java/org/apache/commons/io/IOExceptionList.java         | 2 +-
 src/test/java/org/apache/commons/io/IOExceptionListTestCase.java | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/io/IOExceptionList.java 
b/src/main/java/org/apache/commons/io/IOExceptionList.java
index 6bc6cc2..d4dc326 100644
--- a/src/main/java/org/apache/commons/io/IOExceptionList.java
+++ b/src/main/java/org/apache/commons/io/IOExceptionList.java
@@ -52,7 +52,7 @@ public class IOExceptionList extends IOException {
      * @since 2.9.0
      */
     public IOExceptionList(final String message, final List<? extends 
Throwable> causeList) {
-        super(message, causeList == null ? null : causeList.get(0));
+        super(message, causeList == null || causeList.isEmpty() ? null : 
causeList.get(0));
         this.causeList = causeList == null ? Collections.emptyList() : 
causeList;
     }
 
diff --git a/src/test/java/org/apache/commons/io/IOExceptionListTestCase.java 
b/src/test/java/org/apache/commons/io/IOExceptionListTestCase.java
index d001d14..9a13bc6 100644
--- a/src/test/java/org/apache/commons/io/IOExceptionListTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOExceptionListTestCase.java
@@ -50,6 +50,12 @@ public class IOExceptionListTestCase {
     }
 
     @Test
+    public void testEmptyList() {
+        new IOExceptionList(Collections.emptyList());
+        new IOExceptionList("foo", Collections.emptyList());
+    }
+
+    @Test
     public void testMessageCause() {
         final EOFException cause = new EOFException();
         final List<EOFException> list = Collections.singletonList(cause);

Reply via email to