You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2014/05/08 00:12:56 UTC

svn commit: r1593148 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVParser.java test/java/org/apache/commons/csv/CSVParserTest.java

Author: sebb
Date: Wed May  7 22:12:56 2014
New Revision: 1593148

URL: http://svn.apache.org/r1593148
Log:
CSV-113 Check whether ISE/IAE are being used appropriately

Modified:
    commons/proper/csv/trunk/src/changes/changes.xml
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/changes/changes.xml?rev=1593148&r1=1593147&r2=1593148&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Wed May  7 22:12:56 2014
@@ -40,6 +40,7 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBD" description="First release">
+        <action issue="CSV-113" type="fix" dev="sebb">Check whether ISE/IAE are being used appropriately</action>
         <action issue="CSV-114" type="fix" dev="sebb">CSVFormat constructor should reject a header array with duplicate entries</action>
         <action issue="CSV-112" type="fix" dev="britter">HeaderMap is inconsistent when it is parsed from an input with duplicate columns names</action>
         <action issue="CSV-111" type="fix" dev="ggregory">CSVRecord.toMap() fails if row length shorter than header length</action>

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java?rev=1593148&r1=1593147&r2=1593148&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java Wed May  7 22:12:56 2014
@@ -236,7 +236,7 @@ public final class CSVParser implements 
      * @throws IllegalArgumentException
      *             If the parameters of the format are inconsistent or if either reader or format are null.
      * @throws IOException
-     *             If an I/O error occurs
+     *             If there is a problem reading the header or skipping the first record
      */
     public CSVParser(final Reader reader, final CSVFormat format) throws IOException {
         Assertions.notNull(reader, "reader");
@@ -352,6 +352,7 @@ public final class CSVParser implements 
      * Initializes the name to index mapping if the format defines a header.
      *
      * @return null if the format has no header.
+     * @throws IOException if there is a problem reading the header or skipping the first record
      */
     private Map<String, Integer> initializeHeader() throws IOException {
         Map<String, Integer> hdrMap = null;
@@ -377,7 +378,7 @@ public final class CSVParser implements 
             if (header != null) {
                 for (int i = 0; i < header.length; i++) {
                     if (hdrMap.containsKey(header[i])) {
-                        throw new IllegalStateException("The header contains duplicate names: " +
+                        throw new IllegalArgumentException("The header contains duplicate names: " +
                                 Arrays.toString(header));
                     }
                     hdrMap.put(header[i], Integer.valueOf(i));

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1593148&r1=1593147&r2=1593148&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Wed May  7 22:12:56 2014
@@ -492,7 +492,7 @@ public class CSVParserTest {
         parser.close();
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testDuplicateHeaderEntries() throws Exception {
         CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[]{}));
     }