JDK-7120291 : (fmt) ArrayIndexOutOfBoundsException when formatting a zero value
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-12-11
  • Updated: 2013-08-13
  • Resolved: 2013-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Server VM (build 21.1-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux mizar 2.6.32-36-generic #79-Ubuntu SMP Tue Nov 8 22:29:26 UTC 2011 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
A statement like:

System.out.println(String.format("%5.1g", v2));

rises an exception if variable v2 is set to 0 (zero).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run the following java program:

package test;

public class Test {

    public static void main(String[] args) {
        
        double v = 0.0;
        
        System.out.println(String.format("%5.1g", v));
    }
}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting:

0.0


ACTUAL -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at java.util.Formatter$FormatSpecifier.addZeros(Formatter.java:3401)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:3295)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:3190)
	at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2757)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2708)
	at java.util.Formatter.format(Formatter.java:2488)
	at java.util.Formatter.format(Formatter.java:2423)
	at java.lang.String.format(String.java:2845)
	at test.Test.main(Test.java:13)


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:3401)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:3295)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:3190)
	at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2757)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2708)
	at java.util.Formatter.format(Formatter.java:2488)
	at java.util.Formatter.format(Formatter.java:2423)
	at java.lang.String.format(String.java:2845)
	at test.Test.main(Test.java:13)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

public class Test {

    public static void main(String[] args) {
        
        double v = 0.0;
        
        System.out.println(String.format("%5.1g", v));
    }
}

---------- END SOURCE ----------

Comments
Duplicate of JDK-6469160.
13-08-2013