JDK-8038144 : (fmt) Formatter fails to format "%.1g" with 0 as argument
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 7u21
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-02-27
  • Updated: 2014-04-16
  • Resolved: 2014-04-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_21"
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-5)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Formatter throws an java.lang.ArrayIndexOutOfBoundsException when the format string is "%.1g" and the value is 0. 
It is ok with a non-null value.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the attached code


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 test.main(test.java:7)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Formatter;

public class test {

    public static void main(String[] args) {
	Formatter fmt = new Formatter();
	fmt.format("%.1g", 0.);

	System.out.println(fmt.toString());
    }
}
---------- END SOURCE ----------


Comments
This is a duplicate of 6469160, which is fixed in jdk8. It's not a regression and we have no plans to fix it in jdk7 until escalated.
16-04-2014