-
Bug
-
Resolution: Fixed
-
P3
-
1.1.4
-
1.2beta4
-
sparc
-
solaris_2.5
-
Verified
Name: dfC67450 Date: 01/26/98
java.text.ChoiceFormat.ctor(double[] limits, String[] formats) does not check
whether lengths of input arrays are equal.
Javadoc says:
* When creating a ChoiceFormat, you must specify an array of formats
* and an array of limits. The length of these arrays must be the same.
Because of this an unexpected exception may be thrown if, for example,
formats.length < limits.length.
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.text.*;
public class Test {
public static void main (String args[]){
double[] limits = {1, 2, 3};
String[] formats = {"one", "two"};
ChoiceFormat cf = new ChoiceFormat(limits, formats);
System.out.println(cf.format(5));
}
}
---------Output from the test---------------------
java.lang.ArrayIndexOutOfBoundsException: 2
at java.text.ChoiceFormat.format(ChoiceFormat.java)
at java.text.ChoiceFormat.format(ChoiceFormat.java)
at java.text.NumberFormat.format(NumberFormat.java)
at Test.main(Test.java:8)
--------------------------------------------------
======================================================================