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
This commit is contained in:
Sebastian Bazley 2014-05-07 22:12:56 +00:00
parent 16b175b01a
commit 88a7e755e6
3 changed files with 5 additions and 3 deletions

View File

@ -40,6 +40,7 @@ The <action> type attribute can be add,update,fix,remove.
<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>

View File

@ -236,7 +236,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* @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 Iterable<CSVRecord>, Closeable {
* 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 Iterable<CSVRecord>, Closeable {
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));

View File

@ -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[]{}));
}