Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7181749

Integer.decode("0b1010101") fails

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      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.

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: