FULL PRODUCT VERSION :
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
In computer, negative integer use complement code to store. So Integer.MIN_VALUE= -2^31, Ineger.MAX_VALUE=2^31-1 and abs(Integer.MIN_VALUE) = abs(Integer.MAX_VALUE)+1.
If I use: Integer.toBinaryString(Integer.MIN_VALUE), then output 10000000000000000000000000000000 , it use complementation to represent.
The problem is as follows:
If I use Integer.parseInt("10000000000000000000000000000000",2), it throws an exception, but ideally it should output -2147483648, that is Integer.MIN_VALUE.
I think Y=Integer.parseInt(X,2) and X=Integer.toBinaryString(Y) should be always true.
I think jdk may not implement this special condition.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
System.out.println(Integer.parseInt(Integer.toBinaryString(Integer.MIN_VALUE),2));
will show this bug.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
-2147483648
ACTUAL -
Exception in thread "main" java.lang.NumberFormatException: For input string: "10000000000000000000000000000000"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Test.main(Test.java:3)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NumberFormatException: For input string: "10000000000000000000000000000000"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Test.main(Test.java:3)
REPRODUCIBILITY :
This bug can be reproduced always.