A DESCRIPTION OF THE REQUEST :
I'm using a library for parsing CSV files, which automatically binds csv values to java beans.
If the CSV contains a value like 09 that should be mapped to an integer field, it uses, behind the scenes, Integer.decode method.
This method checks if the string passed as input starts with 0x, 0X, 0 in order to determine the radix, so if I pass 09 (imagining that it's a simple 9 in decimal-base), it throws an uncomplete exception message
JUSTIFICATION :
When this code is used by third-party libraries, one may not know this feature of the decode method and the exception does not help to point out immediatly where the problem is: why input string "9" cannot be converted to integer?
Adding the radix to the exception message, will help to understand that this number is not converted to an integer because it's not decoded in decimal base.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Integer.decode("09")
java.lang.NumberFormatException: For input string: "9", radix 8
if radix is different from 10
ACTUAL -
Integer.decode("09")
java.lang.NumberFormatException: For input string: "9"
---------- BEGIN SOURCE ----------
String value = "09";
Integer.decode(value);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
String value = "09";
value = value.replaceFirst("^0+(?!$","")
Integer.decode(value);
I'm using a library for parsing CSV files, which automatically binds csv values to java beans.
If the CSV contains a value like 09 that should be mapped to an integer field, it uses, behind the scenes, Integer.decode method.
This method checks if the string passed as input starts with 0x, 0X, 0 in order to determine the radix, so if I pass 09 (imagining that it's a simple 9 in decimal-base), it throws an uncomplete exception message
JUSTIFICATION :
When this code is used by third-party libraries, one may not know this feature of the decode method and the exception does not help to point out immediatly where the problem is: why input string "9" cannot be converted to integer?
Adding the radix to the exception message, will help to understand that this number is not converted to an integer because it's not decoded in decimal base.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Integer.decode("09")
java.lang.NumberFormatException: For input string: "9", radix 8
if radix is different from 10
ACTUAL -
Integer.decode("09")
java.lang.NumberFormatException: For input string: "9"
---------- BEGIN SOURCE ----------
String value = "09";
Integer.decode(value);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
String value = "09";
value = value.replaceFirst("^0+(?!$","")
Integer.decode(value);