Skip to content

Commit fa15e2b

Browse files
committed
CSVParser.nextRecord() should throw CSVException (an IOException
subclass) instead of IOException and IllegalStateException, no method signature changes needed
1 parent 29f9fd8 commit fa15e2b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/changes/changes.xml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<release version="1.13.0" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
4444
<!-- FIX -->
4545
<action type="fix" issue="CSV-314" dev="ggregory" due-to="Gary Gregory">Required OSGi Import-Package version numbers in MANIFEST.MF #504.</action>
46+
<action type="fix" issue="CSV-314" dev="ggregory" due-to="Gary Gregory">CSVParser.nextRecord() should throw CSVException (an IOException subclass) instead of IOException and IllegalStateException, no method signature changes needed.</action>
4647
<!-- ADD -->
4748
<action type="add" issue="CSV-313" dev="ggregory" due-to="Gary Gregory">Add CSVPrinter.getRecordCount().</action>
4849
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use CSVParser.Builder and builder() and deprecate CSVParser constructors.</action>

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ final class CSVRecordIterator implements Iterator<CSVRecord> {
208208
/**
209209
* Gets the next record.
210210
*
211+
* @throws IOException on parse error or input read-failure
212+
* @throws CSVException on invalid input.
211213
* @return the next record.
212214
*/
213215
private CSVRecord getNextRecord() {
@@ -498,8 +500,8 @@ public CSVParser(final Reader reader, final CSVFormat format) throws IOException
498500
* @throws IllegalArgumentException
499501
* If the parameters of the format are inconsistent or if either the reader or format is null.
500502
* @throws IOException
501-
* If there is a problem reading the header or skipping the first record
502-
* @throws CSVException Thrown on invalid input.
503+
* if there is a problem reading the header or skipping the first record
504+
* @throws CSVException on invalid input.
503505
* @since 1.1
504506
* @deprecated Will be private in the next major version, use {@link Builder#get()}.
505507
*/
@@ -547,7 +549,7 @@ private Map<String, Integer> createEmptyHeaderMap() {
547549
*
548550
* @return null if the format has no header.
549551
* @throws IOException if there is a problem reading the header or skipping the first record
550-
* @throws CSVException Thrown on invalid input.
552+
* @throws CSVException on invalid input.
551553
*/
552554
private Headers createHeaders() throws IOException {
553555
Map<String, Integer> hdrMap = null;
@@ -830,7 +832,7 @@ public Iterator<CSVRecord> iterator() {
830832
*
831833
* @return the record as an array of values, or {@code null} if the end of the stream has been reached
832834
* @throws IOException on parse error or input read-failure
833-
* @throws CSVException Thrown on invalid input.
835+
* @throws CSVException on invalid input.
834836
*/
835837
CSVRecord nextRecord() throws IOException {
836838
CSVRecord result = null;
@@ -855,7 +857,7 @@ CSVRecord nextRecord() throws IOException {
855857
}
856858
break;
857859
case INVALID:
858-
throw new IOException("(line " + getCurrentLineNumber() + ") invalid parse sequence");
860+
throw new CSVException("(line %,d) invalid parse sequence", getCurrentLineNumber());
859861
case COMMENT: // Ignored currently
860862
if (sb == null) { // first comment for this record
861863
sb = new StringBuilder();
@@ -866,7 +868,7 @@ CSVRecord nextRecord() throws IOException {
866868
reusableToken.type = TOKEN; // Read another token
867869
break;
868870
default:
869-
throw new IllegalStateException("Unexpected Token type: " + reusableToken.type);
871+
throw new CSVException("Unexpected Token type: %s", reusableToken.type);
870872
}
871873
} while (reusableToken.type == TOKEN);
872874

0 commit comments

Comments
 (0)