-
Bug
-
Resolution: Fixed
-
P4
-
1.1.6, 1.1.7, 1.2.0
-
beta
-
generic, sparc
-
generic, solaris_2.5, solaris_2.6
Name: dfC67450 Date: 02/13/98
java.text.MessageFormat.applyPattern(String pattern) limits the number of
occurences of arguments in the pattern to 10.
Javadoc says:
* messageFormatPattern := string ( "{" messageFormatElement "}" string )*
*
* messageFormatElement := argument { "," elementFormat }
*
* elementFormat := "time" { "," datetimeStyle }
* | "date" { "," datetimeStyle }
* | "number" { "," numberStyle }
* | "choice" { "," choiceStyle }
*
* datetimeStyle := "short"
* | "medium"
* | "long"
* | "full"
* | dateFormatPattern
*
* numberStyle := "currency"
* | "percent"
* | "integer"
* | numberFormatPattern
*
*
*
* The argument is a number from 0 to 9, which corresponds to the
* arguments presented in an array to be formatted.
It limits maximum number of the *different* arguments only.
Here is the test demonstrating the bug. It first prints
ten arguments with no problem, then prints 11 arguments and
gets an error IllegalArgumentException: argument number too large.
-----------------Test2.java------------------------
import java.text.*;
public class Test2 {
public static void main (String args[]){
Object[] testArgs = {"x"};
MessageFormat mf = new MessageFormat("");
String pattern = "1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}";
System.out.println("pattern1: " + pattern);
mf.applyPattern(pattern);
System.out.println("formatted: " + mf.format(testArgs));
pattern = "1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}11{0}";
System.out.println();
System.out.println("pattern2: " + pattern);
mf.applyPattern(pattern);
System.out.println(mf.toPattern());
System.out.println("formatted: " + mf.format(testArgs));
}
}
---------Output from the test---------------------
pattern1: 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}
formatted: 1x2x3x4x5x6x7x8x9x10x
pattern2: 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}11{0}
java.lang.IllegalArgumentException: argument number too large at
at java.text.MessageFormat.makeFormat(MessageFormat.java)
at java.text.MessageFormat.applyPattern(MessageFormat.java)
at Test2.main(Test2.java:14)
--------------------------------------------------
======================================================================
Name: krT82822 Date: 04/19/99
MessageFormat constrains it's arguments to 0..9. This has
become quite a bottleneck for us as we have many formats greater
than 10. Looking at the course [source? -KR] it appears the only constraint
on the argument number is the size of an int, used by a private
format() methed to detect recursion.
We'd love to have an unlimited number of arguments. However, it
seems the restriction of 0..9 could be easily raised to 0..31 if
the only constaint on the size is indeed the size of an int (or
0..63 if the int became a long) in addition to adding smarts for
parsing a 2-digit vs. 1-digit number.
======================================================================
java.text.MessageFormat.applyPattern(String pattern) limits the number of
occurences of arguments in the pattern to 10.
Javadoc says:
* messageFormatPattern := string ( "{" messageFormatElement "}" string )*
*
* messageFormatElement := argument { "," elementFormat }
*
* elementFormat := "time" { "," datetimeStyle }
* | "date" { "," datetimeStyle }
* | "number" { "," numberStyle }
* | "choice" { "," choiceStyle }
*
* datetimeStyle := "short"
* | "medium"
* | "long"
* | "full"
* | dateFormatPattern
*
* numberStyle := "currency"
* | "percent"
* | "integer"
* | numberFormatPattern
*
*
*
* The argument is a number from 0 to 9, which corresponds to the
* arguments presented in an array to be formatted.
It limits maximum number of the *different* arguments only.
Here is the test demonstrating the bug. It first prints
ten arguments with no problem, then prints 11 arguments and
gets an error IllegalArgumentException: argument number too large.
-----------------Test2.java------------------------
import java.text.*;
public class Test2 {
public static void main (String args[]){
Object[] testArgs = {"x"};
MessageFormat mf = new MessageFormat("");
String pattern = "1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}";
System.out.println("pattern1: " + pattern);
mf.applyPattern(pattern);
System.out.println("formatted: " + mf.format(testArgs));
pattern = "1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}11{0}";
System.out.println();
System.out.println("pattern2: " + pattern);
mf.applyPattern(pattern);
System.out.println(mf.toPattern());
System.out.println("formatted: " + mf.format(testArgs));
}
}
---------Output from the test---------------------
pattern1: 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}
formatted: 1x2x3x4x5x6x7x8x9x10x
pattern2: 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9{0}10{0}11{0}
java.lang.IllegalArgumentException: argument number too large at
at java.text.MessageFormat.makeFormat(MessageFormat.java)
at java.text.MessageFormat.applyPattern(MessageFormat.java)
at Test2.main(Test2.java:14)
--------------------------------------------------
======================================================================
Name: krT82822 Date: 04/19/99
MessageFormat constrains it's arguments to 0..9. This has
become quite a bottleneck for us as we have many formats greater
than 10. Looking at the course [source? -KR] it appears the only constraint
on the argument number is the size of an int, used by a private
format() methed to detect recursion.
We'd love to have an unlimited number of arguments. However, it
seems the restriction of 0..9 could be easily raised to 0..31 if
the only constaint on the size is indeed the size of an int (or
0..63 if the int became a long) in addition to adding smarts for
parsing a 2-digit vs. 1-digit number.
======================================================================
- duplicates
-
JDK-4211119 MessageFormat has an undocumented limit of 10 substitutions.
- Closed