Skip to content

Validate input to setDelimiter(String) for empty string#266

Merged
garydgregory merged 1 commit into
apache:masterfrom
mykolaf:delimcheck
Oct 15, 2022
Merged

Validate input to setDelimiter(String) for empty string#266
garydgregory merged 1 commit into
apache:masterfrom
mykolaf:delimcheck

Conversation

@mykolaf

@mykolaf mykolaf commented Sep 27, 2022

Copy link
Copy Markdown

Signed-off-by: Mykola Faryma m.faryma@partner.samsung.com

The addition of String delimiter support opened a new opportunity to set the delimiter as empty string. This situation will result in NegativeArraySizeException (see example below). I propose to enhance argument checking in setDelimiter(String delimiter) to get explicit and helpful exception in such case.

Log:

Exception in thread "main" java.lang.NegativeArraySizeException: -1
        at org.apache.commons.csv.Lexer.<init>(Lexer.java:75)
        at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:435)
        at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:403)
        at org.apache.commons.csv.CSVParser.parse(CSVParser.java:303)
        at Test.main(Test.java:10)

Test code:

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;

import java.io.StringReader;

public class Test {
    public static void main(String[] args) throws Exception {

        CSVParser.parse("abcd", CSVFormat.Builder.create().setDelimiter("").build());
    }
}

Signed-off-by: Mykola Faryma <m.faryma@partner.samsung.com>
@mykolaf mykolaf marked this pull request as ready for review September 27, 2022 10:34
@garydgregory garydgregory changed the title Check setDelimiter() for empty string Validate input to setDelimiter(String) for empty string Oct 15, 2022
@garydgregory garydgregory merged commit 23c39b1 into apache:master Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants