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

java.text.DecimalFormat.parse() fails when multiplier is set to 2, 4, 8, 16, ..

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: dfC67450 Date: 03/03/99



      java.text.DecimalFormat.parse(String text, ParsePosition pp) incorrectly parses
      Long.MIN_VALUE if multiplier is set to 2, 4, 8, 16 etc. It should return
      negative values.
       
      Here is the test demonstrating the bug:

      -----------------TestM.java------------------------
      import java.text.*;

      public class TestM {
          public static void main (String args[]){
              boolean passed = true;
              DecimalFormat df = new DecimalFormat();
              String str = Long.toString(Long.MIN_VALUE);
              for (int m = 1; m <= 100; m++) {
                df.setMultiplier(m);
                long n = ((Long) df.parse(str, new ParsePosition(0))).longValue();
                if (n > 0) {
                  System.out.println("------------------------------------");
                  System.out.println(" multiplier = " + df.getMultiplier());
                  System.out.println(" text: " + str);
                  System.out.println(" parsed: " + n);
                  passed = false;
                }
             }
             if (passed) System.out.println("Test passed");
             else System.out.println("Test failed");
          }
      }
      ---------Output from the test---------------------
        multiplier = 2
        text: -9223372036854775808
        parsed: 4611686018427387904
      ------------------------------------
        multiplier = 4
        text: -9223372036854775808
        parsed: 2305843009213693952
      ------------------------------------
        multiplier = 8
        text: -9223372036854775808
        parsed: 1152921504606846976
      ------------------------------------
        multiplier = 16
        text: -9223372036854775808
        parsed: 576460752303423488
      ------------------------------------
        multiplier = 32
        text: -9223372036854775808
        parsed: 288230376151711744
      ------------------------------------
        multiplier = 64
        text: -9223372036854775808
        parsed: 144115188075855872
      ------------------------------------
      Test failed
      --------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            aliusunw Alan Liu (Inactive)
            Reporter:
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: