Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
FULL PRODUCT VERSION : java version "1.6.0-beta2" Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86) Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows XP [Version 5.1.2600] EXTRA RELEVANT SYSTEM CONFIGURATION : Using Eclipse 3.2 A DESCRIPTION OF THE PROBLEM : The following code produces an ArrayIndexOutOfBoundsException: import java.util.Formatter ... Formatter f = new Formatter(); f.format("%.1g", 0.0); // <- exception thrown here ... STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile and run the above code snippet... EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - No exception thrown... ACTUAL - Exception thrown ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at java.util.Formatter$FormatSpecifier.addZeros(Formatter.java:3356) at java.util.Formatter$FormatSpecifier.print(Formatter.java:3250) at java.util.Formatter$FormatSpecifier.print(Formatter.java:3145) at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2717) at java.util.Formatter$FormatSpecifier.print(Formatter.java:2666) at java.util.Formatter.format(Formatter.java:2432) at java.util.Formatter.format(Formatter.java:2366) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.util.Formatter public class App { public static void main(String args[]) { Formatter f = new Formatter(); f.format("%.1g", 0.0); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Use any of the following for the format string: "%.2g" "%.1f" "%.1e" They all work, but obviously are not exact workarounds...