-
Bug
-
Resolution: Fixed
-
P3
-
1.1.6, 1.2.0
-
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
--------------------------------------------------
======================================================================
- relates to
-
JDK-8150702 change in javadoc for parseObject for MessageFormat - JDK-8073211
- Closed
-
JDK-8073211 javadoc of Format parseObject methods should specify NullPointerExceptions
- Closed