commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CSV-96) CSVRecord does not verify that the length of the header mapping matches the number of values
Date Thu, 28 Mar 2013 13:09:15 GMT

    [ https://issues.apache.org/jira/browse/CSV-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13616224#comment-13616224
] 

Gary Gregory edited comment on CSV-96 at 3/28/13 1:07 PM:
----------------------------------------------------------

How about this then:

{code:java}
    /**
     * Creates a new record.
     * 
     * @param values not null
     * @param mapping may be null
     * @param comment may be null
     * @param recordNumber record number, not the line number
     */
    CSVRecord(final String[] values, final Map<String, Integer> mapping,
            final String comment, final long recordNumber) {
        if (mapping != null && values.length != mapping.size()) {
            throw new IllegalArgumentException(String.format(
                    "Expected record length (%,d) to match header length (%,d) for record
%,d", values.length,
                    mapping.size(), recordNumber));
        }
        this.recordNumber = recordNumber;
        this.values = values;
        this.mapping = mapping;
        this.comment = comment;
    }

{code}
                
      was (Author: garydgregory):
    How about this then:

{code:java}
    CSVRecord(final String[] values, final Map<String, Integer> mapping,
            final String comment, final long recordNumber) {
        if (mapping != null && values.length != mapping.size()) {
            throw new IllegalArgumentException(String.format(
                    "Expected record length (%,d) to match header length (%,d) for record
%,d", values.length,
                    mapping.size(), recordNumber));
        }
        this.recordNumber = recordNumber;
        this.values = values != null ? values : EMPTY_STRING_ARRAY;
        this.mapping = mapping;
        this.comment = comment;
    }
{code}
                  
> CSVRecord does not verify that the length of the header mapping matches the number of
values
> --------------------------------------------------------------------------------------------
>
>                 Key: CSV-96
>                 URL: https://issues.apache.org/jira/browse/CSV-96
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.0
>            Reporter: Benedikt Ritter
>             Fix For: 1.0
>
>
> CSVRecord does not verify that the size of the header mapping matches the number of values.
The following test will produce a ArrayOutOfBoundsException:
> {code}
> @Test
> public void testInvalidHeaderTooLong() throws Exception {
>    final CSVParser parser = new CSVParser("a,b", CSVFormat.newBuilder().withHeader("A",
"B", "C").build());
>    final CSVRecord record = parser.iterator().next();
>    record.get("C");
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message