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

MessageFormat does not throw IllegalArgumentException for invalid format

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
       MessageFormat.format("Test {0,number,invalid_style}", new Object[] { 42 }); doesn't throw IAE.
      The class-level documentation defines what constitutes a valid pattern, specifying that only certain combinations of FormatType and FormatStyle are legal:

      MessageFormat Class Doc : "The FormatType and FormatStyle values are used to create a Format instance for the format element. The following table shows how the values map to Format instances. Combinations not shown in the table are illegal."

      And obviously invalid_style is not a valid style for number. So I think this should be an invalid combination.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      throw IAE
      ACTUAL -
      Test invalid_style42

      ---------- BEGIN SOURCE ----------
      var str = MessageFormat.format("Test {0,number,invalid_style}", new Object[] { 42 });
      System.out.println(str);
      ---------- END SOURCE ----------

        1. Test.java
          0.2 kB
          Patricia Tavares

            jlu Justin Lu
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: