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

MessageFormat fails to perform substitution

XMLWordPrintable

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



      Name: ssT124754 Date: 04/02/2001


      java version "1.3.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
      Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)

      MessageFormat fails to perform the proper substitution.
      The test program contains 2 similar examples. The first example is a skeletal
      version of the second. The first one performs the substitution, the second one
      ignores it.but it should not ignore it.

      public class Test {

          private static MessageFormat TEST1 = new MessageFormat(
              "<>" +
                  tr(td("?") +
                     td("<>")) +
                  tr(td("?") +
                     td("<>")) +
                  tr(td("?") +
                     td("<>")) +
                  tr(td("") + td("{0}")) +
              "</>" +
              "<=\"\">" +
              "<p>" +
              "{1}" +
              "<=\"\">");

          private static MessageFormat TEST2 = new MessageFormat(
              "<table>" +
                  tr(td("Offer cancellation and rescheduling?") +
                     td("<input type=checkbox>")) +
                  tr(td("Use the customer's name?") +
                     td("<input type=checkbox>")) +
                  tr(td("Include a callback number?") +
                     td("<input type=checkbox>")) +
                  tr(td("Callback number") + td("{0}")) +
              "</table>" +
              "<input type=submit value=\"save changes\">" +
              "<p>" +
              "Test these settings by calling {1} <br> " +
              "<input type=submit value=\"call now\">");

          private static FieldPosition IGNORE = new FieldPosition(0);

          public static void main(String[] ignored)
              throws Exception
          {
              StringBuffer out = new StringBuffer();
              Object[] args = new Object[] {"phone #1" , "phone#2"};
              TEST1.format(args,out,IGNORE);
              TEST2.format(args,out,IGNORE);
              System.out.println(out.toString());
          }

          private static String tr(String s) {
              return "<tr>" + s + "</tr>";
          }

          private static String td(String s) {
              return "<td>" + s + "</td>";
          }
      }

      Output looks like:

      <><tr><td>?</td><td><></td></tr><tr><td>?</td><td><></td></tr><tr><td>?</td><td>
      <></td></tr><tr><td></td><td>phone #1</td></tr></><=""><p>phone#2<=""><table><tr
      ><td>Offer cancellation and rescheduling?</td><td><input type=checkbox></td></tr
      ><tr><td>Use the customers name?</td><td><input type=checkbox></td></tr><tr><td>
      Include a callback number?</td><td><input type=checkbox></td></tr><tr><td>Callba
      ck number</td><td>{0}</td></tr></table><input type=submit value="save changes"><
      p>Test these settings by calling {1} <br> <input type=submit value="call now">

      The thing to note is that {0} and {1} don't get substituted for in example #2.
      (Review ID: 119995)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: