Initialize the message of an IOExceptionList to a default if null.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -123,6 +123,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-756" dev="ggregory" type="fix" due-to="wodencafe, Gary Gregory, Bruno P. Kinoshita">
Update FileWriterWithEncoding to extend ProxyWriter #296.
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ Initialize the message of an IOExceptionList to a default if null.
+ </action>
<!-- ADD -->
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add BrokenReader.INSTANCE.

MODIFY
src/main/java/org/apache/commons/io/IOExceptionList.java
src/main/java/org/apache/commons/io/IOExceptionList.java
public class IOExceptionList extends IOException {
private static final long serialVersionUID = 1L;
+ private static String toMessage(final List<? extends Throwable> causeList) {
+ return String.format("%,d exceptions: %s", causeList == null ? 0 : causeList.size(), causeList);
+ }
+
private final List<? extends Throwable> causeList;
/**
* @param causeList a list of cause exceptions.
*/
public IOExceptionList(final List<? extends Throwable> causeList) {
- this(String.format("%,d exceptions: %s", causeList == null ? 0 : causeList.size(), causeList), causeList);
+ this(toMessage(causeList), causeList);
}
/**
@@ -52,7 +56,7 @@ public IOExceptionList(final List<? extends Throwable> causeList) {
* @since 2.9.0
*/
public IOExceptionList(final String message, final List<? extends Throwable> causeList) {
- super(message, causeList == null || causeList.isEmpty() ? null : causeList.get(0));
+ super(message != null ? message : toMessage(causeList), causeList == null || causeList.isEmpty() ? null : causeList.get(0));
this.causeList = causeList == null ? Collections.emptyList() : causeList;
}

MODIFY
src/test/java/org/apache/commons/io/IOExceptionListTest.java
src/test/java/org/apache/commons/io/IOExceptionListTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.EOFException;
@@ -79,6 +80,14 @@ public void testNullCause() {
assertTrue(sqlExceptionList.getCauseList().isEmpty());
}
+ @Test
+ public void testNullMessageArg() {
+ assertNotNull(new IOExceptionList(null, Collections.emptyList()).getMessage());
+ assertNotNull(new IOExceptionList(null, null).getMessage());
+ assertEquals("A", new IOExceptionList("A", Collections.emptyList()).getMessage());
+ assertEquals("A", new IOExceptionList("A", null).getMessage());
+ }
+
@Test
public void testPrintStackTrace() {
final EOFException cause = new EOFException();

Initialize the message of an IOExceptionList to a default if null.