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

MessageFormat.format() method fails to replace placeholders if the pattern used to create the MessageFormat is not escaped

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux den00blt 3.8.13-44.1.1.el6uek.x86_64 #2 SMP Wed Sep 10 06:10:25 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When creating a MessageFormat using the constructor MessageFormat(String pattern, Locale locale), if the pattern has a single non escaped characters like ' (apostrophe) prior to a placeholder {0} in the pattern, the placeholders are not replaced by calling the messageFormat.format(Object[], StringBuffer, null). But if the non escaped character is after the placeholder, the placeholder would be replaced.

      Example:

      Couldn't play game : {0} --> {0} here would not be replaced with actual content
      whereas
      Playing {0} wasn't possible -> {0} here would be properly replaced with actual content.


      REGRESSION. Last worked in version 8u112

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      MessageFormat mf = new MessageFormat(pattern, locale);
      mf.format(args, new StringBuffer(1000), null)

      use pattern = Couldn't play game : {0}
      locale = en
      args[0] = "Mario"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Couldn't play game : mario
      ACTUAL -
      Couldn't play game : {0}

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      MessageFormat mf = new MessageFormat(pattern, locale);
      mf.format(args, new StringBuffer(1000), null)

      use pattern = Couldn't play game : {0}
      locale = en
      args[0] = "Mario"
      ---------- END SOURCE ----------

      SUPPORT :
      YES

            nishjain Nishit Jain
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: