Skip to content

Commit c36d6cd

Browse files
committed
CSVParser.parse(InputStream, Charset, CSVFormat) with a null CSVFormat
maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat))
1 parent 088672f commit c36d6cd

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<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>
4949
<action type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(File, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action>
5050
<action type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(Path, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action>
51+
<action type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.parse(InputStream, Charset, CSVFormat) with a null CSVFormat maps to CSVFormat.DEFAULT (like CSVParser.parse(Reader, CSVFormat)).</action>
5152
<!-- ADD -->
5253
<action type="add" dev="ggregory" due-to="Gary Gregory">Define and use Maven property commons.jmh.version.</action>
5354
<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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,11 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF
329329
* </p>
330330
*
331331
* @param inputStream
332-
* an InputStream containing CSV-formatted input. Must not be null.
332+
* an InputStream containing CSV-formatted input, {@code null} maps to {@link CSVFormat#DEFAULT}.
333333
* @param charset
334334
* The Charset to decode the given file.
335335
* @param format
336-
* the CSVFormat used for CSV parsing. Must not be null.
336+
* the CSVFormat used for CSV parsing, {@code null} maps to {@link CSVFormat#DEFAULT}.
337337
* @return a new CSVParser configured with the given reader and format.
338338
* @throws IllegalArgumentException
339339
* If the parameters of the format are inconsistent or if either reader or format are null.
@@ -342,10 +342,8 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF
342342
* @throws CSVException Thrown on invalid input.
343343
* @since 1.5
344344
*/
345-
@SuppressWarnings("resource")
346345
public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format)
347346
throws IOException {
348-
Objects.requireNonNull(inputStream, "inputStream");
349347
return parse(new InputStreamReader(inputStream, charset), format);
350348
}
351349

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.io.File;
3535
import java.io.IOException;
36+
import java.io.InputStream;
3637
import java.io.InputStreamReader;
3738
import java.io.PipedReader;
3839
import java.io.PipedWriter;
@@ -1432,6 +1433,15 @@ public void testParseFileCharsetNullFormat() throws IOException {
14321433
}
14331434
}
14341435

1436+
@Test
1437+
public void testParseInputStreamCharsetNullFormat() throws IOException {
1438+
try (InputStream in = Files.newInputStream(Paths.get("src/test/resources/org/apache/commons/csv/CSVFileParser/test.csv"));
1439+
CSVParser parser = CSVParser.parse(in, Charset.defaultCharset(), null)) {
1440+
// null maps to DEFAULT.
1441+
parseFully(parser);
1442+
}
1443+
}
1444+
14351445
@Test
14361446
public void testParseNullFileFormat() {
14371447
assertThrows(NullPointerException.class, () -> CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT));

0 commit comments

Comments
 (0)