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

java.text.MessageFormat.parse has different behavior in case of null

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 03/02/98



      Object[] java.text.MessageFormat.parse(String text, ParsePosition pp) has different
      behavior in case of text == null. If MessageFormat pattern is empty string it
      returns array of length 10 filled with nulls. If pattern is not empty it throws
      NullPointerException.

      Here is the test demonstrating the bug:

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

      public class TestMF {
          public static void main (String args[]){
            String[] patterns = {"", "one", "{0,date,short}"};
            MessageFormat mf = new MessageFormat("");
        
            for (int i = 0; i < patterns.length; i++) {
              String pattern = patterns[i];
              mf.applyPattern(pattern);
              try {
                Object[] array = mf.parse(null, new ParsePosition(0));
                System.out.println("pattern: \"" + pattern + "\"");
                System.out.print(" parsedObjects: {");
                for (int j = 0; j < array.length; j++) {
                  if (array[j] != null) System.out.print("\"" + array[j].toString() + "\"");
                  else System.out.print("null");
                  if (j < array.length - 1) System.out.print(",");
                }
                System.out.println("}") ;
              } catch (Exception e) {
                System.out.println("pattern: \"" + pattern + "\"");
                System.out.println(" Exception: " + e.toString());
              }
            }
              
          }

      }

      ---------Output from the test ---------------------
      pattern: ""
        parsedObjects: {null,null,null,null,null,null,null,null,null,null}
      pattern: "one"
        Exception: java.lang.NullPointerException
      pattern: "{0,date,short}"
        Exception: java.lang.NullPointerException
      --------------------------------------------------

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: