Question regarding java.util.Formatter width

Brandon Passanisi brandon.passanisi at
Tue Nov 22 00:13:01 UTC 2011

Hello core-libs-dev.  I am currently investigating the issues regarding 
the following bug:

I have spent a good amount of time stepping through the simple 
TestFormat code supplied in the bug report.  I noticed some interesting 
behavior when running the following line in the test which throws the 

    System.out.printf("%0.4f\n", 56789.456789);

During the execution of this line, the Formatter class appears to treat 
the "0" not as a width value, which the author of the bug report 
intended, but rather as a flag value.  "0" is a valid flag value 
indicating that the result will be zero-padded.  But, in this case the 
author of the bug report intended to use the "0" as a width value, 
citing the Formatter specification text "The optional width is a 
non-negative decimal integer indicating the minimum number of characters 
to be written to the output.".  Using the "0" in this manner results in 
a MissingFormatWidthException.  Since "0" can be a flag value and also a 
width value, I am wondering if we have found some sort of gray area in 
the specification.

So, my questions are:

    1. Is there possibly some specification text that needs to be used
    to disallow "0" for a width value?
    2. Or, is a value of "0" allowed to be used for both a flag value
    and width value?
    3. If question #2 is true, can "0" be used for both a flag and a
    width value at the same time?  I ask this because the current
    behavior appears to not work when running the following line:

        System.out.printf("%00.4f\n", 56789.456789);

        Exception in thread "main"
        java.util.DuplicateFormatFlagsException: Flags = '0'
             at java.util.Formatter$Flags.parse(
             at java.util.Formatter.parse(
             at java.util.Formatter.format(

Oracle <>
Brandon Passanisi | Principle Member of Technical Staff

Oracle Java Standards Conformance

Green Oracle <> Oracle is committed to 
developing practices and products that help protect the environment

More information about the core-libs-dev mailing list