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 41362db16e59cf41c122d63337372657f4bde7b7 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Mar 14 15:55:57 2025 -0400 CSVParser.parse(URL, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)) --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/csv/CSVParser.java | 5 ++--- src/test/java/org/apache/commons/csv/CSVParserTest.java | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c7deab3b..8b00e71c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -44,6 +44,7 @@ <!-- 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> <!-- 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 6163f2ed..df25206e 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -346,7 +346,6 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) throws IOException { Objects.requireNonNull(inputStream, "inputStream"); - Objects.requireNonNull(format, "format"); return parse(new InputStreamReader(inputStream, charset), format); } @@ -385,7 +384,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { * @param reader * a Reader containing CSV-formatted input. Must not be null. * @param format - * the CSVFormat used for CSV parsing, {@code null} uses {@link CSVFormat#DEFAULT}. + * the CSVFormat used for CSV parsing, {@code null} maps to {@link CSVFormat#DEFAULT}. * @return a new CSVParser configured with the given reader and format. * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either reader or format are null. @@ -431,7 +430,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { * @param charset * the charset for the resource. 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 url, charset or format are null. diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index f95c0e07..6a4fe934 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -1459,8 +1459,12 @@ public class CSVParserTest { } @Test - public void testParseUrlCharsetNullFormat() { - assertThrows(NullPointerException.class, () -> CSVParser.parse(new URL("https://commons.apache.org"), Charset.defaultCharset(), null)); + public void testParseUrlCharsetNullFormat() throws IOException { + final ClassLoader loader = ClassLoader.getSystemClassLoader(); + final URL url = loader.getResource("org/apache/commons/csv/CSVFileParser/test.csv"); + try (CSVParser parser = CSVParser.parse(url, Charset.defaultCharset(), null)) { + // null maps to DEFAULT. + } } @Test