JDK-7181749 : Integer.decode("0b1010101") fails
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-07-04
  • Updated: 2012-07-23
  • Resolved: 2012-07-23
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
  From the Javadoc for Integer.decode(String) in Java 7.

DecimalNumeral, HexDigits, and OctalDigits are as defined in section 3.10.1 of The Java��� Language Specification, except that underscores are not accepted between digits.

However, this section defines a format new to Java 7; BinaryNumeral

A binary numeral consists of the leading ASCII characters 0b or 0B followed by one or more of the ASCII digits 0 or 1 interspersed with underscores, and can represent a positive, zero, or negative integer.

For consistency, this method should decode BinaryNumeral as well.



JUSTIFICATION :
For consistency.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Decode binary numerals.
ACTUAL -
Throws a NumberFormatException

---------- BEGIN SOURCE ----------
int i = 0b1010101;
int j = Integer.decode("0b1010101");
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Parse such Strings without calling this method.

Comments
EVALUATION Duplicate of functionality requested in comments of 6863378; closing accordingly.
23-07-2012