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

ChoiceFormat.applyPattern fails with ArrayIndexOutOfBoundsException error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • x86
    • windows_nt



      Name: skT45625 Date: 11/08/2000


      java version "1.2.2"
      HotSpot VM (1.0.1, mixed mode, build g)

      i wrote the following code :

      package test;

      import java.text.*;
      import java.io.*;

      public class ChoiceFormatTester {


      public static final double[] doublesZ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      10, 11, 12, 13, 14, 15, 16, 17, 18, 19,20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
      30, 31, 32, 33, 34, 35};

      public static final String[] stringsZ = {"0", "1", "2", "3", "4", "5",
      "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "G", "H", "I", "J","K", "L",
      "M", "N", "O", "P", "Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z"};


        public static void main(String[] args) {
            ChoiceFormat choiceFormat = null;
            String formatString = "";
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            
            try {
                 System.out.println("choiceZ = new ChoiceFormat(doublesZ, stringsZ)");
                 ChoiceFormat choiceZ = new ChoiceFormat(doublesZ, stringsZ);
                 formatString = choiceZ.toPattern();
                 System.out.println("choiceZ.toPattern() : <"+formatString+">");
                 choiceFormat = new ChoiceFormat(formatString);
            } catch (Exception e) {
                e.printStackTrace();
                try {
                in.readLine();
                        } catch (IOException ioe) {
                              ioe.printStackTrace();
                        }
                  }
        }
      }//end of class


      The output is :

      choiceZ = new ChoiceFormat(doublesZ, stringsZ)
      choiceZ.toPattern() : <0.0#0|1.0#1|2.0#2|3.0#3|4.0#4|5.0#5|6.0#6|7.0#7|8.0#8|9.0
      #9|10.0#A|11.0#B|12.0#C|13.0#D|14.0#E|15.0#F|16.0#G|17.0#H|18.0#I|19.0#J|20.0#K|
      21.0#L|22.0#M|23.0#N|24.0#O|25.0#P|26.0#Q|27.0#R|28.0#S|29.0#T|30.0#U|31.0#V|32.
      0#W|33.0#X|34.0#Y|35.0#Z>
      java.lang.ArrayIndexOutOfBoundsException: 30
              at java.text.ChoiceFormat.applyPattern(ChoiceFormat.java:203)
              at java.text.ChoiceFormat.<init>(ChoiceFormat.java:279)
              at test.ChoiceFormatTester.main(ChoiceFormatTester.java:37)

      ###@###.### 2000-11-08
      ChoiceFormat(String pattern) seems to fail when the supplied string, format/limit is greater
      than a size of 30
      (Review ID: 111975)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: