JDK-4116444 : java.text.MessageFormat.parse has different behavior in case of null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.6,1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1998-03-02
  • Updated: 2016-03-23
  • Resolved: 1998-03-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.0 1.2beta4Fixed
Related Reports
Relates :  
Relates :  
Description

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
--------------------------------------------------

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

Comments
I think this fix was wrong.
23-03-2016

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2beta4 INTEGRATED IN: 1.2beta4 VERIFIED IN: 1.2fcs
14-06-2004

EVALUATION bug fixed in new putback.
11-06-2004