Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 1c7a991

Browse files
committed
[CSV-201] Do not use RuntimeException in CSVParser.iterator().new
Iterator() {...}.getNextRecord(). Use an IllegalStateException instead (KISS for now, no need for a custom exception)
1 parent b2a50d4 commit 1c7a991

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<action issue="CSV-193" type="fix" dev="ggregory" due-to="Matthias Wiehl">Fix incorrect method name 'withFirstRowAsHeader' in user guide.</action>
4444
<action issue="CSV-171" type="fix" dev="ggregory" due-to="Gary Gregory, Michael Graessle, Adrian Bridgett">Negative numeric values in the first column are always quoted in minimal mode.</action>
4545
<action issue="CSV-187" type="update" dev="ggregory" due-to="Gary Gregory">Update platform requirement from Java 6 to 7.</action>
46+
<action issue="CSV-201" type="update" dev="ggregory" due-to="Benedikt Ritter, Gary Gregory">Do not use RuntimeException in CSVParser.iterator().new Iterator() {...}.getNextRecord()</action>
4647
<action issue="CSV-189" type="add" dev="ggregory" due-to="Peter Holzwarth, Gary Gregory">CSVParser: Add factory method accepting InputStream.</action>
4748
<action issue="CSV-190" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVFormat.print(File, Charset)</action>
4849
<action issue="CSV-191" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVFormat.print(Path, Charset)</action>

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,14 @@ public boolean isClosed() {
501501
/**
502502
* Returns an iterator on the records.
503503
*
504-
* <p>IOExceptions occurring during the iteration are wrapped in a
505-
* RuntimeException.
506-
* If the parser is closed a call to {@code next()} will throw a
507-
* NoSuchElementException.</p>
504+
* <p>
505+
* An {@link IOException} caught during the iteration are re-thrown as an
506+
* {@link IllegalStateException}.
507+
* </p>
508+
* <p>
509+
* If the parser is closed a call to {@link Iterator#next()} will throw a
510+
* {@link NoSuchElementException}.
511+
* </p>
508512
*/
509513
@Override
510514
public Iterator<CSVRecord> iterator() {
@@ -515,8 +519,8 @@ private CSVRecord getNextRecord() {
515519
try {
516520
return CSVParser.this.nextRecord();
517521
} catch (final IOException e) {
518-
// TODO: This is not great, throw an ISE instead?
519-
throw new RuntimeException(e);
522+
throw new IllegalStateException(
523+
e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
520524
}
521525
}
522526

0 commit comments

Comments
 (0)