Menu

#40 ParseBoolean will cause an exception if trueValue and falseValue are provided in upper-case

Outstanding
closed
nobody
None
1
2015-01-04
2013-11-12
fbastian
No

Hi,

If I instantiate a ParseBoolean like this:
new ParseBool("T", "F")
I will get an exception:
org.supercsv.exception.SuperCsvCellProcessorException: 'T' could not be parsed as a Boolean

Because of line 210 in org.supercsv.cellprocessor.ParseBool:
final String stringValue = ((String) value).toLowerCase();

=> my parameter is upper-case, but the ParseBool transforms the values in my file into lower-case.
In that case, trueValues and falseValues should be populated with values in lower case, for instance:
trueValues.add(trueValue.toLowerCase());

Discussion

  • James Bassett

    James Bassett - 2013-11-14

    Hi,

    The default ParseBool should support T/F already, but regarding the lowercase issue..

    This isn't a bug - it's the documented behaviour. If you read the javadoc for ParseBool it says:

    Converts a String to a Boolean.

    The default values for true are: "true", "1", "y", "t"

    The default values for false are: "false", "0", "n", "f"

    The input is converted to lowercase before comparison against the true/false values (to handle all variations of case in the input), so if you supply your own true/false values then ensure they are lowercase.

    I'll change this ticket to a feature request - maybe the default constructor should use all permutations (t/T/f/F/etc) and not convert the input to lowercase. I guess the only reason it hasn't changed is to provide backwards-compatibility.

     
  • James Bassett

    James Bassett - 2013-11-14

    Ticket moved from /p/supercsv/bugs/48/

     
  • James Bassett

    James Bassett - 2015-01-04
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.