Skip to content

Commit 35d7843

Browse files
author
Gary Gregory
committed
Fix IndexOutOfBoundsException in IOExceptionList contructors.
1 parent 4654ca2 commit 35d7843

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/org/apache/commons/io/IOExceptionList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IOExceptionList(final List<? extends Throwable> causeList) {
5252
* @since 2.9.0
5353
*/
5454
public IOExceptionList(final String message, final List<? extends Throwable> causeList) {
55-
super(message, causeList == null ? null : causeList.get(0));
55+
super(message, causeList == null || causeList.isEmpty() ? null : causeList.get(0));
5656
this.causeList = causeList == null ? Collections.emptyList() : causeList;
5757
}
5858

src/test/java/org/apache/commons/io/IOExceptionListTestCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public void testCause() {
4949
assertEquals(list, causeList);
5050
}
5151

52+
@Test
53+
public void testEmptyList() {
54+
new IOExceptionList(Collections.emptyList());
55+
new IOExceptionList("foo", Collections.emptyList());
56+
}
57+
5258
@Test
5359
public void testMessageCause() {
5460
final EOFException cause = new EOFException();

0 commit comments

Comments
 (0)