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

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 6
    • Component/s: 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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: