United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4112090 java.text.MessageFormat.applyPattern has undocumented limits
4112090 : java.text.MessageFormat.applyPattern has undocumented limits

Details
Type:
Bug
Submit Date:
1998-02-13
Status:
Resolved
Updated Date:
2000-12-13
Project Name:
JDK
Resolved Date:
2000-12-13
Component:
core-libs
OS:
solaris_2.5,solaris_2.6,generic
Sub-Component:
java.text
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1.6,1.1.7,1.2.0
Fixed Versions:
1.4.0

Related Reports
Duplicate:

Sub Tasks

Description
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.
======================================================================

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
merlin

FIXED IN:
merlin-beta

INTEGRATED IN:
merlin-beta


                                     
2004-06-14
SUGGESTED FIX

Remove the restriction that only 10 arguments are allowed in a pattern.
                                     
2004-06-11
WORK AROUND

None
                                     
2004-06-11
EVALUATION

Am sending email to Alan Liu (###@###.###) to check if this 
limitation should be documented as part of the spec or as an 
implementation detail.
doug.kramer@Eng 1998-09-21

Alan Liu and Laura Werner agreed that since we don't document this,
we should consider it an implementation "bug" (or rfe) and change the implementation to allow more than 10 arguments.  So I am changing this 
from a doc bug to a classes_text bug, and am lowering the priority from 
3 to 4 since it's a minor bug that doesn't need to be fixed for 1.2 FCS.
doug.kramer@Eng 1998-09-23

The i18n team decided to document the limitation instead of extending the limitation in the code.  This will minimize the risks of regressing other part of JDK on this dependency.
###@###.### 1999-04-20

[xueming.shen@Japan 1999-05-12]
Alan, would you please document the limitation and do the putback together
with other IBM stuff?


The limitation should be removed, rather than documenting it.
masayoshi.okutsu@Eng 2000-02-01


Note that the two parts of the description are about two separate limitations:
1) the undocumented limitation that the total number of messageFormatElement parts in a format cannot exceed 10.
2) the well-documented limitation that the argument number cannot exceed 9.
Changing the first is a bug fix, changing the second a specification change.
norbert.lindenberg@Eng 2000-03-15


Both limitations have been removed for Merlin.
norbert.lindenberg@Eng 2000-12-06
                                     
2000-03-15



Hardware and Software, Engineered to Work Together