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 49b13ef Initialize the message of an IOExceptionList to a default if
null.
49b13ef is described below
commit 49b13ef698bf15e57bdff66c5f67887e8e0eb865
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Nov 6 08:41:09 2021 -0400
Initialize the message of an IOExceptionList to a default if null.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/io/IOExceptionList.java | 8 ++++++--
src/test/java/org/apache/commons/io/IOExceptionListTest.java | 9 +++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5754e0f..33d75cb 100644
--- a/src/changes/changes.xml
+++ b/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.
diff --git a/src/main/java/org/apache/commons/io/IOExceptionList.java
b/src/main/java/org/apache/commons/io/IOExceptionList.java
index d4dc326..6e394e9 100644
--- a/src/main/java/org/apache/commons/io/IOExceptionList.java
+++ b/src/main/java/org/apache/commons/io/IOExceptionList.java
@@ -33,6 +33,10 @@ import java.util.List;
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;
/**
@@ -41,7 +45,7 @@ public class IOExceptionList extends IOException {
* @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 class IOExceptionList extends IOException {
* @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;
}
diff --git a/src/test/java/org/apache/commons/io/IOExceptionListTest.java
b/src/test/java/org/apache/commons/io/IOExceptionListTest.java
index 476f531..7a41ee3 100644
--- a/src/test/java/org/apache/commons/io/IOExceptionListTest.java
+++ b/src/test/java/org/apache/commons/io/IOExceptionListTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.io;
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;
@@ -80,6 +81,14 @@ public class IOExceptionListTest {
}
@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();
final List<EOFException> list = Collections.singletonList(cause);