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
commit 931531bcd8e333372f05fc19f670dd5a9ecfd219 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Mar 14 16:01:45 2025 -0400 CSVParser.parse(String, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)) --- src/changes/changes.xml | 3 ++- src/main/java/org/apache/commons/csv/CSVParser.java | 3 +-- src/test/java/org/apache/commons/csv/CSVParserTest.java | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8b00e71c..bca27da3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -44,7 +44,8 @@ <!-- FIX --> <action type="fix" issue="CSV-317" dev="ggregory" due-to="Filipe Roque">Release history link changed from changes-report.html to changes.html #516.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80).</action> - <action type="fix" issue="CSV-317" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(URL, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(URL, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(String, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Define and use Maven property commons.jmh.version.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVFormat.Builder.setMaxRows(long).</action> diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index df25206e..42c44558 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -403,7 +403,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { * @param string * a CSV string. Must not be null. * @param format - * the CSVFormat used for CSV parsing. Must not be null. + * the CSVFormat used for CSV parsing, {@code null} maps to {@link CSVFormat#DEFAULT}. * @return a new parser * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either string or format are null. @@ -413,7 +413,6 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { */ public static CSVParser parse(final String string, final CSVFormat format) throws IOException { Objects.requireNonNull(string, "string"); - Objects.requireNonNull(format, "format"); return parse(new StringReader(string), format); } diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index 6a4fe934..df9f0d8b 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -1454,8 +1454,17 @@ public class CSVParserTest { } @Test - public void testParseStringNullFormat() { - assertThrows(NullPointerException.class, () -> CSVParser.parse("csv data", (CSVFormat) null)); + public void testParseStringNullFormat() throws IOException { + try (CSVParser parser = CSVParser.parse("1,2,3", null)) { + // null maps to DEFAULT. + final List<CSVRecord> records = parser.getRecords(); + assertEquals(1, records.size()); + final CSVRecord record = records.get(0); + assertEquals(3, record.size()); + assertEquals("1", record.get(0)); + assertEquals("2", record.get(1)); + assertEquals("3", record.get(2)); + } } @Test