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

java.text.DecimalFormat.format() throws unexpected exception

XMLWordPrintable

    • 1.1.6
    • sparc
    • solaris_2.5
    • Verified



        Name: dfC67450 Date: 11/04/97



        java.text.DecimalFormat.format(double n, StringBuffer str, FieldPosition fp) throws
        unexpected ArrayIndexOutOfBoundsException if maximumFractionDigits setting is
        greater than some limit. This limit depends on value of n.
         
        Here is the test demonstrating the bug:

        -----------------Test.java------------------------
        import java.text.*;
        import java.math.*;
        public class Test {
            public static void main (String args[]){
                double d = 1;
                System.out.println("d = " + d);
                DecimalFormat df = new DecimalFormat();
                StringBuffer sb;
                FieldPosition fp;
                for (int i = 17; i <= 20; i++) {
                  df.setMaximumFractionDigits(i);
                  sb = new StringBuffer("");
                  fp = new FieldPosition(0);
                  System.out.println(" getMaximumFractionDigits() = " + i);
                  System.out.println(" formated: " + df.format(d, sb, fp));
                  System.out.println();
                }
            }
        }

        ---------Output from the test---------------------
        d = 1.0
          getMaximumFractionDigits() = 17
          formated: 1
         
          getMaximumFractionDigits() = 18
          formated: 1
         
          getMaximumFractionDigits() = 19
          formated: 0.9223372036854775807
         
          getMaximumFractionDigits() = 20
        java.lang.ArrayIndexOutOfBoundsException: 19
                at java.text.DigitList.set(DigitList.java)
                at java.text.DecimalFormat.format(DecimalFormat.java)
                at Test2.main(Test2.java:15)
        --------------------------------------------------

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

              joconnersunw John Oconner (Inactive)
              dfazunensunw Dmitri Fazunenko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: