Name: rmT116609 Date: 09/02/2004
A DESCRIPTION OF THE REQUEST :
Byte.parseByte("FF", 16) throws a NumberFormatException. This seems rather illogical since "FF" is a perfectly respectable byte value of -1. The behavior of parseByte, parseShort, parseInt, and parseLong is such that a leading minus sign is required when parsing negative numbers. So parseByte("-1", 16) works but parseByte("FF", 16) does not.
A handy enhancement would be to overload parseByte etc. with something like this:
byte parseByte(String s, int radix, boolean acceptTwosCompliment)
So parseByte("FF", 16) or parseByte("FF", 16, false) would throw NumberFormatException, completely preserving backward compatability, but parseByte("FF", 16, true) would return -1. Of course there would be similar enhancements to Short, Integer, and Long.
JUSTIFICATION :
The API should provide a simple way to, e.g, parse string "FF" into a byte. Currently, one would have to call parseInt and manipulate the result into a byte.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
As mentioned above:
parseByte("FF", 16, true) should return -1 and
parseByte("FF", 16) should continue to throw NumberFormatException.
CUSTOMER SUBMITTED WORKAROUND :
Use parseInt and examine the result.
(Incident Review ID: 301049)
======================================================================