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

java.text.MessageFormat.format has undocumented behavior

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 02/24/98



      Javadoc is silent about output of java.text.MessageFormat.format(Object[] objs,
      StringBuffer result, FieldPosition fp) in case of objs == null or
      objs.length == 0 or objs[i] == null for some i.

      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.text.*;

      public class Test {
          public static void main (String args[]){
              MessageFormat mf = new MessageFormat("<{0}>");
              Object[] objs1 = null;
              Object[] objs2 = {};
              Object[] objs3 = {null};
              System.out.println("pattern: \"" + mf.toPattern() + "\"");
              System.out.print("format(null) : ");
              System.out.println("\"" + mf.format(objs1) + "\"");
              System.out.print("format({}) : ");
              System.out.println("\"" + mf.format(objs2) + "\"");
              System.out.print("format({null}) :");
              System.out.println("\"" + mf.format(objs3) + "\"");
          }
      }
       
      ---------Output from the test for 1.2-beta3 ---------------------
      pattern: "<{0}>"
      format(null) : "<{0}>"
      format({}) : "<{0}>"
      format({null}) :java.lang.NullPointerException
              at java.text.MessageFormat.format(MessageFormat.java:674)
              at java.text.MessageFormat.format(MessageFormat.java:453)
              at java.text.Format.format(Format.java:128)
              at Test.main(Test.java:15)
      ---------Output from the test for 1.1.6 ---------------------
      pattern: "<{0}>"
      format(null) : java.lang.NullPointerException
              at java.text.MessageFormat.format(MessageFormat.java)
              at java.text.MessageFormat.format(MessageFormat.java)
              at java.text.Format.format(Format.java)
              at Test.main(Test.java:11)
      --------------------------------------------------

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: