Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4106659

java.text.ChoiceFormat.ctor(double[], String[]) doesn't perform any checkings

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



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

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

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: