mirror of
https://github.com/apache/commons-csv.git
synced 2025-02-28 13:59:07 +00:00
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:
parent
16b175b01a
commit
88a7e755e6
@ -40,6 +40,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="1.0" date="TBD" description="First release">
|
<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-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-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>
|
<action issue="CSV-111" type="fix" dev="ggregory">CSVRecord.toMap() fails if row length shorter than header length</action>
|
||||||
|
@ -236,7 +236,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* If the parameters of the format are inconsistent or if either reader or format are null.
|
* If the parameters of the format are inconsistent or if either reader or format are null.
|
||||||
* @throws IOException
|
* @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 {
|
public CSVParser(final Reader reader, final CSVFormat format) throws IOException {
|
||||||
Assertions.notNull(reader, "reader");
|
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.
|
* Initializes the name to index mapping if the format defines a header.
|
||||||
*
|
*
|
||||||
* @return null if the format has no 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 {
|
private Map<String, Integer> initializeHeader() throws IOException {
|
||||||
Map<String, Integer> hdrMap = null;
|
Map<String, Integer> hdrMap = null;
|
||||||
@ -377,7 +378,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||||||
if (header != null) {
|
if (header != null) {
|
||||||
for (int i = 0; i < header.length; i++) {
|
for (int i = 0; i < header.length; i++) {
|
||||||
if (hdrMap.containsKey(header[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));
|
Arrays.toString(header));
|
||||||
}
|
}
|
||||||
hdrMap.put(header[i], Integer.valueOf(i));
|
hdrMap.put(header[i], Integer.valueOf(i));
|
||||||
|
@ -492,7 +492,7 @@ public class CSVParserTest {
|
|||||||
parser.close();
|
parser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testDuplicateHeaderEntries() throws Exception {
|
public void testDuplicateHeaderEntries() throws Exception {
|
||||||
CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[]{}));
|
CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[]{}));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user