Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6344301

(fmt) java.util.Formatter specified exception is not thrown

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • generic
    • windows_xp

      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

            bpassani Brandon Passanisi
            ynovozhi Yulia Novozhilova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: