Send a Java Program Into An Infinite Loop
Compile this program and run it; the program will hang (at least it does on a 32-bit system with the latest JRE/JDK):class ujjwal{ public static void main(String[] args) { System.out.println("Test:"); double d = Double.parseDouble("2.2250738585072012e-308"); System.out.println("Value: " + d); } }
Send the Java Compiler Into An Infinite Loop
Try to compile this program; the compiler will hang:class compilehang { public static void main(String[] args) { double d = 2.2250738585072012e-308; System.out.println("Value: " + d); } }
Where’s the Problem?
For the runtime case at least, Konstantin has narrowed the problem down to the “correction loop” in FloatingDecimal.java. See his comments on my PHP bug analysis article.Like PHP, Java gets stuck crossing the normalized/unnormalized border,
Bug Report
Konstantin reported this problem to Oracle three weeks ago, but is still waiting for a reply. (Update: as per Konstantin’s comment below, the bug has been assigned “internal review ID of 1949967, which is NOT visible on the Sun Developer Network (SDN)”.)Update: Previous Bug Reports Describe the Same Problem
Readers found two bug reports that describe the same problem (although not in terms of the magic number 2.2250738585072012e-308): bug number 100119 from 2009, and bug number 4421494 from 2001. (But don’t bother clicking on that last one — the link is now dead, as of 2/3/11.)Addendum
As pointed out in the comments below, equivalent forms of the number cause the problem as well; examples:- 0.00022250738585072012e-304 (decimal point placement)
- 00000000002.2250738585072012e-308 (leading zeros)
- 2.225073858507201200000e-308 (trailing zeros)
- 2.2250738585072012e-00308 (leading zeros in the exponent)
- 2.2250738585072012997800001e-308 (superfluous digits beyond digit 17)
No comments:
Post a Comment