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

MessageFormat doesn't replace {0} if followed by word with apostrophe

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_2000



      Name: rmT116609 Date: 03/27/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1)01-b01, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Windows 2000 5.00.2195 Service Pack 3

      ADDITIONAL OPERATING SYSTEMS :
      AIX 5.1


      A DESCRIPTION OF THE PROBLEM :
      When I am using French strings, the string with the word d'acces before the {0}, causes the {0} to not get replaced in a MessageFormat. Removing the apostrophe fixes it. Changing this to a double apostrophe works for that word, but breaks regular strings without the {0}. Can duplicate using the following code.

      import java.text.*;

      public class Msgfmtexample
      {
      static public void main(String args[])
      {
              MessageFormat msgFormatsingle = new MessageFormat
      ("Le chemin d'accès {0} est déjà validé.");
              Object argObjsingle[] = {"some path"};
              String formatsingle = msgFormatsingle.format
      (argObjsingle);
              System.out.println("Formatted msg with single
      apostrophe: " + formatsingle);

              MessageFormat msgFormatdouble = new MessageFormat
      ("Le chemin d''accès {0} est déjà validé.");
              Object argObjdouble[] = {"some path"};
              String formatdouble = msgFormatdouble.format
      (argObjdouble);
              System.out.println("Formatted msg with double
      apostrophe: " + formatdouble);
              
              System.out.println("Regular msg with single
      apostrophes: this'n that'n");
              System.out.println("Regular msg with double
      apostrophes: this''n that''n");
          }
          
      }


      Output looks like:
      Formatted msg with single apostrophe: Le chemin daccès {0}
      est déjà validé.
      Formatted msg with double apostrophe: Le chemin d'accès
      some path est déjà validé.
      Regular msg with single apostrophes: this'n that'n
      Regular msg with double apostrophes: this''n that''n



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See sample code in desription section.

      1. Compile and run.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      see description section

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.*;

      public class Msgfmtexample
      {
      static public void main(String args[])
      {
              MessageFormat msgFormatsingle = new MessageFormat("Le chemin d'accès
      {0} est déjà validé.");
              Object argObjsingle[] = {"some path"};
              String formatsingle = msgFormatsingle.format(argObjsingle);
              System.out.println("Formatted msg with single apostrophe: " +
      formatsingle);

              MessageFormat msgFormatdouble = new MessageFormat("Le chemin d''accès
      {0} est déjà validé.");
              Object argObjdouble[] = {"some path"};
              String formatdouble = msgFormatdouble.format(argObjdouble);
              System.out.println("Formatted msg with double apostrophe: " +
      formatdouble);
              
              System.out.println("Regular msg with single apostrophes: this'n
      that'n");
              System.out.println("Regular msg with double apostrophes: this''n
      that''n");
          }
          
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Only thing I've found is to use a double apostrophe in that word only if it precedes the {0}. If in a regular string, the double apostrophe gets displayed.
      (Review ID: 181147)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: