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

Parsing of binary representation of Long fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u26
    • core-libs
    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.0.6002]

      A DESCRIPTION OF THE PROBLEM :
      According to the documentation using negative numbers while parsing Longs should be allowed, as the java docs states:

           * parseLong("-0", 10) returns 0L
           * parseLong("-FF", 16) returns -255L
           * parseLong("1100110", 2) returns 102L


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      System.out.println(Long.parseLong(Long.toBinaryString(Long.MIN_VALUE),2));



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      -9223372036854775808

      ACTUAL -
      Exception in thread "main" java.lang.NumberFormatException: For input string: "1111111111111111111111111111111111111111111111111111111111111111"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Long.parseLong(Long.java:422)
      at Test.main(Test.java:4)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NumberFormatException: For input string: "1111111111111111111111111111111111111111111111111111111111111111"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Long.parseLong(Long.java:422)
      at Test.main(Test.java:4)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      System.out.println(Long.parseLong(Long.toBinaryString(Long.MIN_VALUE),2));
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: