A DESCRIPTION OF THE REQUEST :
Each of the following lines of code will fail with a
NumberFormatException when executed.
Integer.decode("+10");
Integer.parseInt("+10");
JUSTIFICATION :
Since both the decode and parseInt methods of the Integer class already support a leading minus sign, why not check for and ignore a leading plus sign.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the following to work:
Integer.decode("+10");
Integer.parseInt("+10");
ACTUAL -
Both Integer.decode and Integer.parseInt fail with a
NumberFormatException when the integer string starts with a plus sign.
---------- BEGIN SOURCE ----------
int i = Integer.decode("+10");
int j = Integer.parseInt("+10");
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
User program has to check for and remoce any leading plus sign.
###@###.### 2005-2-25 13:05:47 GMT
Each of the following lines of code will fail with a
NumberFormatException when executed.
Integer.decode("+10");
Integer.parseInt("+10");
JUSTIFICATION :
Since both the decode and parseInt methods of the Integer class already support a leading minus sign, why not check for and ignore a leading plus sign.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the following to work:
Integer.decode("+10");
Integer.parseInt("+10");
ACTUAL -
Both Integer.decode and Integer.parseInt fail with a
NumberFormatException when the integer string starts with a plus sign.
---------- BEGIN SOURCE ----------
int i = Integer.decode("+10");
int j = Integer.parseInt("+10");
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
User program has to check for and remoce any leading plus sign.
###@###.### 2005-2-25 13:05:47 GMT
- duplicates
-
JDK-5017980 Allow signed positive integer to be parsed instead of a NumerFormatException
-
- Closed
-