JDK-6344301 : (fmt) java.util.Formatter specified exception is not thrown
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: generic
  • Submitted: 2005-11-01
  • Updated: 2012-03-23
  • Resolved: 2011-11-28
Related Reports
Duplicate :  
Description
1) Specification of java.util.Formatter says that greneral conversion:
------------Spec--------------------
's'  	 '\u0073'  	 Produces a string.

If the argument is null, then the result is "null". If the argument implements Formattable, then its formatTo method is invoked. Otherwise, the result is obtained by invoking the argument's toString() method.

If the '#' flag is given and the argument is not a Formattable , then a FormatFlagsConversionMismatchException will be thrown. 
----------------------------
But when I use flag '#' with Date argument, exception is not thrown.
===============Code=============
import java.util.Formatter;
import java.util.Date;

public class FormatTest {
    public static void main(String[] args) {
        Formatter formatter = new Formatter();
        Date notFormattable = new Date();
        formatter.format("%1$#s", notFormattable);
        System.out.println("Exception expected");
    }
}
==============Output===============
Exception expected