MessageFormat pattern quoting logic breaks with ChoiceFormat subformat

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 25
    • Component/s: core-libs
    • None
    • generic
    • generic

      MessageFormat provides functionality to escape '{' and '}' which are reserved chars for a MessageFormat pattern. However, escaping these quotes never works for a ChoiceFormat subformat, since MessageFormat utilizes a recursive implementation; the recursed MessageFormat re-parses the already parsed pattern (which no longer has the escaped quotes), treating escaped brackets as non-escaped brackets.

      Actual
      jshell> var m = new MessageFormat("{0,choice,0#foo|1#bar|2#Longer foo '{0}' {0} bar baz}")
      jshell> $m.format(new Object[]{2})
      $9 ==> "Longer foo 2 2 bar baz"

      Expected
      I would expect "Longer foo {0} 2 bar baz"

      Another example is
      jshell> var m = new MessageFormat("bar = {0,choice,0#foo '{' {0} bar }");
      jshell> $m.format(new Object[]{2})

      Throws IAE ("unmatched braces ...")

      I would expect that it returns "bar =foo { 2 bar", but instead it throws an IAE because the first quoted bracket is parsed as an unquoted bracket, creating uneven brackets which is the cause for the exception.


            Assignee:
            Justin Lu
            Reporter:
            Justin Lu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: