Skip to content

Commit 41362db

Browse files
committed
CSVParser.parse(URL, Charset, CSVFormat) with a null CSVFormat maps to
CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat))
1 parent 1ac1eec commit 41362db

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<!-- FIX -->
4545
<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>
4646
<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>
47+
<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>
4748
<!-- ADD -->
4849
<action type="add" dev="ggregory" due-to="Gary Gregory">Define and use Maven property commons.jmh.version.</action>
4950
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVFormat.Builder.setMaxRows(long).</action>

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF
346346
public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format)
347347
throws IOException {
348348
Objects.requireNonNull(inputStream, "inputStream");
349-
Objects.requireNonNull(format, "format");
350349
return parse(new InputStreamReader(inputStream, charset), format);
351350
}
352351

@@ -385,7 +384,7 @@ public static CSVParser parse(final Path path, final Charset charset, final CSVF
385384
* @param reader
386385
* a Reader containing CSV-formatted input. Must not be null.
387386
* @param format
388-
* the CSVFormat used for CSV parsing, {@code null} uses {@link CSVFormat#DEFAULT}.
387+
* the CSVFormat used for CSV parsing, {@code null} maps to {@link CSVFormat#DEFAULT}.
389388
* @return a new CSVParser configured with the given reader and format.
390389
* @throws IllegalArgumentException
391390
* If the parameters of the format are inconsistent or if either reader or format are null.
@@ -431,7 +430,7 @@ public static CSVParser parse(final String string, final CSVFormat format) throw
431430
* @param charset
432431
* the charset for the resource. Must not be null.
433432
* @param format
434-
* the CSVFormat used for CSV parsing. Must not be null.
433+
* the CSVFormat used for CSV parsing, {@code null} maps to {@link CSVFormat#DEFAULT}.
435434
* @return a new parser
436435
* @throws IllegalArgumentException
437436
* If the parameters of the format are inconsistent or if either url, charset or format are null.

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,12 @@ public void testParseStringNullFormat() {
14591459
}
14601460

14611461
@Test
1462-
public void testParseUrlCharsetNullFormat() {
1463-
assertThrows(NullPointerException.class, () -> CSVParser.parse(new URL("https://commons.apache.org"), Charset.defaultCharset(), null));
1462+
public void testParseUrlCharsetNullFormat() throws IOException {
1463+
final ClassLoader loader = ClassLoader.getSystemClassLoader();
1464+
final URL url = loader.getResource("org/apache/commons/csv/CSVFileParser/test.csv");
1465+
try (CSVParser parser = CSVParser.parse(url, Charset.defaultCharset(), null)) {
1466+
// null maps to DEFAULT.
1467+
}
14641468
}
14651469

14661470
@Test

0 commit comments

Comments
 (0)