CSVParser.getRecords() now throws UncheckedIOException instead of
IOException
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a2c5611..b3311e2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,8 +45,8 @@
       <action issue="CSV-288" type="fix" dev="ggregory" due-to="Santhsoh, Angus">Fix for multi-char delimiter not working as expected #218.</action>

       <action issue="CSV-269" type="fix" dev="ggregory" due-to="Auke te Winkel, Gary Gregory">CSVRecord.get(Enum) should use Enum.name() instead of Enum.toString().</action>

       <action                 type="fix" dev="ggregory" due-to="Gary Gregory">Allow org.apache.commons.csv.IOUtils.copy(Reader, Appendable, CharBuffer) to compile on Java 11 and run on Java 8.</action>

-      <action                 type="fix" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 52 to 53.</action>

       <action issue="CSV-300" type="fix" dev="ggregory" due-to="Markus Spann, Gary Gregory">CSVRecord.toList() does not give write access to the new List.</action>

+      <action                 type="fix" dev="ggregory" due-to="Gary Gregory">CSVParser.getRecords() now throws UncheckedIOException instead of IOException.</action>

       <!-- ADD -->

       <action issue="CSV-291" type="add" dev="ggregory" due-to="Gary Gregory">Make CSVRecord#values() public.</action>

       <action issue="CSV-264" type="add" dev="ggregory" due-to="Sagar Tiwari, Seth Falco, Alex Herbert, Gary Gregory">Add DuplicateHeaderMode for flexibility with header strictness. #114.</action>

@@ -55,6 +55,7 @@
       <action issue="CSV-304" type="add" dev="ggregory" due-to="Peter Hull, Bruno P. Kinoshita, Gary Gregory">Add accessors for header/trailer comments #257.</action>

       <action type="add" dev="ggregory">Add github/codeql-action.</action>

       <!-- UPDATE -->

+      <action                 type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 52 to 53.</action>

       <action                 type="update" dev="kinow" due-to="Dependabot, Gary Gregory">Bump actions/cache from 2.1.6 to 3.0.8 #196, #233, #243.</action>

       <action                 type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/checkout from 2.3.4 to 3.0.2 #188, #195, #220.</action>

       <action                 type="update" dev="ggregory" due-to="Gary Gregory">Bump actions/setup-java from 2 to 3.</action>

diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index ad428d2..bff55a0 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -26,6 +26,7 @@
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringReader;
+import java.io.UncheckedIOException;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
@@ -42,6 +43,7 @@
 import java.util.Spliterator;
 import java.util.Spliterators;
 import java.util.TreeMap;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
@@ -145,8 +147,7 @@
             try {
                 return CSVParser.this.nextRecord();
             } catch (final IOException e) {
-                throw new IllegalStateException(
-                        e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
+                throw new UncheckedIOException(e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
             }
         }
 
@@ -639,16 +640,11 @@
      * </p>
      *
      * @return list of {@link CSVRecord CSVRecords}, may be empty
-     * @throws IOException
+     * @throws UncheckedIOException
      *             on parse error or input read-failure
      */
-    public List<CSVRecord> getRecords() throws IOException {
-        CSVRecord rec;
-        final List<CSVRecord> records = new ArrayList<>();
-        while ((rec = this.nextRecord()) != null) {
-            records.add(rec);
-        }
-        return records;
+    public List<CSVRecord> getRecords() {
+        return stream().collect(Collectors.toList());
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index a7c62da..89a90e3 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -82,6 +82,7 @@
     private static <T extends Throwable> RuntimeException rethrow(final Throwable throwable) throws T {

         throw (T) throwable;

     }

+

     /** The place that the values get written. */

     private final Appendable appendable;

 

diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 25855ca..0761680 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -36,6 +36,7 @@
 import java.io.Reader;

 import java.io.StringReader;

 import java.io.StringWriter;

+import java.io.UncheckedIOException;

 import java.net.URL;

 import java.nio.charset.Charset;

 import java.nio.charset.StandardCharsets;

@@ -106,9 +107,9 @@
             .setHeader("A", "B")

             .build();

 

+    @SuppressWarnings("resource") // caller releases

     private BOMInputStream createBOMInputStream(final String resource) throws IOException {

-        final URL url = ClassLoader.getSystemClassLoader().getResource(resource);

-        return new BOMInputStream(url.openStream());

+        return new BOMInputStream(ClassLoader.getSystemClassLoader().getResource(resource).openStream());

     }

 

     private void parseFully(final CSVParser parser) {

@@ -466,8 +467,6 @@
 

     /**

      * Tests an exported Excel worksheet with a header row and rows that have more columns than the headers

-     *

-     * @throws Exception

      */

     @Test

     public void testExcelHeaderCountLessThanData() throws Exception {

@@ -737,7 +736,7 @@
     public void testGetRecordsFromBrokenInputStream() throws IOException {

         @SuppressWarnings("resource") // We also get an exception on close, which is OK but can't assert in a try.

         final CSVParser parser = CSVParser.parse(new BrokenInputStream(), UTF_8, CSVFormat.DEFAULT);

-        assertThrows(IOException.class, parser::getRecords);

+        assertThrows(UncheckedIOException.class, parser::getRecords);

 

     }