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

java.text.MessageFormat.parse fails with ChoiceFormat

    XMLWordPrintable

Details

    • 1.2beta4
    • x86, sparc
    • solaris_2.5, windows_nt
    • Verified

    Description



      Name: dfC67450 Date: 03/11/98



      Object[] java.text.MessageFormat.parse(String text, ParsePosition pp)
      fails when first formatter is ChoiceFormat and first prefix has length
      greater than 2.

      Here is the test demonstrating the bug:

      -----------------TestMF.java------------------------
      import java.text.*;

      public class TestMF {
          public static void main (String args[]){
              MessageFormat mf = new MessageFormat("");
              String pattern = "{0,choice,1#YES|2#NO}";
              String prefix = "";
              for (int i = 0; i < 5; i++) {
                String formatted = prefix + "YES";
                mf.applyPattern(prefix + pattern);
                prefix += "x";
                Object[] objs = mf.parse(formatted, new ParsePosition(0));
                System.out.println(i + ". pattern :\"" + mf.toPattern() + "\"");
                System.out.print(" \"" + formatted + "\" parsed as ");
                if (objs == null) System.out.println(" null");
                else System.out.println(" " + objs[0]);
              }
          }
      }
      ---------Output from the test ---------------------
      0. pattern :"{0,choice,1.0#YES|2.0#NO}"
       "YES" parsed as 1.0
      1. pattern :"x{0,choice,1.0#YES|2.0#NO}"
       "xYES" parsed as 1.0
      2. pattern :"xx{0,choice,1.0#YES|2.0#NO}"
       "xxYES" parsed as 1.0
      3. pattern :"xxx{0,choice,1.0#YES|2.0#NO}"
       "xxxYES" parsed as null
      4. pattern :"xxxx{0,choice,1.0#YES|2.0#NO}"
       "xxxxYES" parsed as null
      --------------------------------------------------

      ======================================================================

      Attachments

        Activity

          People

            duke J. Duke
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: