Skip to content

Commit 88a7e75

Browse files
committed
CSV-113 Check whether ISE/IAE are being used appropriately
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1593148 13f79535-47bb-0310-9956-ffa450edef68
1 parent 16b175b commit 88a7e75

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The <action> type attribute can be add,update,fix,remove.
4040
<body>
4141

4242
<release version="1.0" date="TBD" description="First release">
43+
<action issue="CSV-113" type="fix" dev="sebb">Check whether ISE/IAE are being used appropriately</action>
4344
<action issue="CSV-114" type="fix" dev="sebb">CSVFormat constructor should reject a header array with duplicate entries</action>
4445
<action issue="CSV-112" type="fix" dev="britter">HeaderMap is inconsistent when it is parsed from an input with duplicate columns names</action>
4546
<action issue="CSV-111" type="fix" dev="ggregory">CSVRecord.toMap() fails if row length shorter than header length</action>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public static CSVParser parse(final URL url, final Charset charset, final CSVFor
236236
* @throws IllegalArgumentException
237237
* If the parameters of the format are inconsistent or if either reader or format are null.
238238
* @throws IOException
239-
* If an I/O error occurs
239+
* If there is a problem reading the header or skipping the first record
240240
*/
241241
public CSVParser(final Reader reader, final CSVFormat format) throws IOException {
242242
Assertions.notNull(reader, "reader");
@@ -352,6 +352,7 @@ public <T extends Collection<CSVRecord>> T getRecords(T records) throws IOExcept
352352
* Initializes the name to index mapping if the format defines a header.
353353
*
354354
* @return null if the format has no header.
355+
* @throws IOException if there is a problem reading the header or skipping the first record
355356
*/
356357
private Map<String, Integer> initializeHeader() throws IOException {
357358
Map<String, Integer> hdrMap = null;
@@ -377,7 +378,7 @@ private Map<String, Integer> initializeHeader() throws IOException {
377378
if (header != null) {
378379
for (int i = 0; i < header.length; i++) {
379380
if (hdrMap.containsKey(header[i])) {
380-
throw new IllegalStateException("The header contains duplicate names: " +
381+
throw new IllegalArgumentException("The header contains duplicate names: " +
381382
Arrays.toString(header));
382383
}
383384
hdrMap.put(header[i], Integer.valueOf(i));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public void testGetHeaderMap() throws Exception {
492492
parser.close();
493493
}
494494

495-
@Test(expected = IllegalStateException.class)
495+
@Test(expected = IllegalArgumentException.class)
496496
public void testDuplicateHeaderEntries() throws Exception {
497497
CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[]{}));
498498
}

0 commit comments

Comments
 (0)