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

BigDecimal.longValueExact() method throws NullPointerException

XMLWordPrintable

    • b03
    • generic
    • generic

        BigDecimal.longValueExact() method throws NullpointerException with 6u14-b01 build.
        Following testcase could be used to reproduce the issue.

        <Code>

        import java.math.BigDecimal;
        class BigDecimalTest
        {
         public static void main(String... args){
                try {
        String longValue = "9223372036854775807.0";
                      BigDecimal bd = new BigDecimal(longValue);
                      long longvalue= bd.longValue();
                      long longValueExact = bd.longValueExact();
                      System.out.println("Test passed ");
                } catch(ArithmeticException e) {
        System.out.println("Test failed ");
                     e.printStackTrace();
                }

            }
        }

        </Code>

        <Output>
        Exception in thread "main" java.lang.NullPointerException
                at java.math.BigDecimal$LongOverflow.check(BigDecimal.java:2974)
                at java.math.BigDecimal.longValueExact(BigDecimal.java:2962)
                at BigDecimalTest.main(BigDecimalTest.java:9)

        </Output>

        java version "1.6.0_14"
        Java(TM) SE Runtime Environment (build 1.6.0_14-b01)
        Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode)


        This test passes with the 6u12-b04 promoted build. Fix for the bug 6622432 may have caused this regression.

              xlu Xiaobin Lu (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: