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-csv.git
The following commit(s) were added to refs/heads/master by this push:
new 7c5c089 Let a null input to CSVRecord#get(Enum) fail in
CSVRecord#get(String).
7c5c089 is described below
commit 7c5c08921c35137b94fa8877f99d088eb13b3941
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jan 20 21:36:11 2020 -0500
Let a null input to CSVRecord#get(Enum) fail in CSVRecord#get(String).
---
src/main/java/org/apache/commons/csv/CSVRecord.java | 3 ++-
src/test/java/org/apache/commons/csv/CSVRecordTest.java | 5 +++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java
b/src/main/java/org/apache/commons/csv/CSVRecord.java
index b7bf53e..471e94d 100644
--- a/src/main/java/org/apache/commons/csv/CSVRecord.java
+++ b/src/main/java/org/apache/commons/csv/CSVRecord.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
/**
* A CSV record parsed from a CSV file.
@@ -65,7 +66,7 @@ public final class CSVRecord implements Serializable,
Iterable<String> {
* @return the String at the given enum String
*/
public String get(final Enum<?> e) {
- return get(e.toString());
+ return get(Objects.toString(e, null));
}
/**
diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index d13e84a..476bac2 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -92,6 +92,11 @@ public class CSVRecordTest {
}
@Test
+ public void testGetNullEnum() {
+ assertThrows(IllegalArgumentException.class, () ->
recordWithHeader.get((Enum<?>) null));
+ }
+
+ @Test
public void testGetUnmappedName() {
assertThrows(IllegalArgumentException.class, () ->
assertNull(recordWithHeader.get("fourth")));
}