@@ -961,6 +961,47 @@ public void testTrim() throws Exception {
961961 Assert .assertEquals (3 , record .size ());
962962 }
963963
964+ @ Test
965+ public void testMissingColumnValuesAreNull () throws Exception {
966+ final String code = ",,\" \" ," ;
967+
968+ // check backward compatibility
969+ try (final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT )) {
970+ final CSVRecord record = parser .iterator ().next ();
971+
972+ assertNotNull (record .get (0 ));
973+ assertNotNull (record .get (1 ));
974+ assertNotNull (record .get (2 ));
975+ assertNotNull (record .get (3 ));
976+ Assert .assertEquals (4 , record .size ());
977+ }
978+
979+ // check withMissingColumnValuesAreNull
980+ try (final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT
981+ .withMissingColumnValuesAreNull ())) {
982+ final CSVRecord record = parser .iterator ().next ();
983+
984+ assertNull (record .get (0 ));
985+ assertNull (record .get (1 ));
986+ assertNotNull (record .get (2 ));
987+ assertNull (record .get (3 ));
988+ Assert .assertEquals (4 , record .size ());
989+ }
990+
991+ // check combination of withNullString and withMissingColumnValuesAreNull
992+ try (final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT
993+ .withNullString ("" )
994+ .withMissingColumnValuesAreNull ())) {
995+ final CSVRecord record = parser .iterator ().next ();
996+
997+ assertNull (record .get (0 ));
998+ assertNull (record .get (1 ));
999+ assertNull (record .get (2 ));
1000+ assertNull (record .get (3 ));
1001+ Assert .assertEquals (4 , record .size ());
1002+ }
1003+ }
1004+
9641005 private void validateLineNumbers (final String lineSeparator ) throws IOException {
9651006 try (final CSVParser parser = CSVParser .parse ("a" + lineSeparator + "b" + lineSeparator + "c" ,
9661007 CSVFormat .DEFAULT .withRecordSeparator (lineSeparator ))) {
0 commit comments