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
------------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
- duplicates
-
JDK-5063507 (fmt) missing exception for "%#s" format specifier
- Resolved