United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6806261 BigDecimal.longValueExact() method throws NullPointerException
6806261 : BigDecimal.longValueExact() method throws NullPointerException

Details
Type:
Bug
Submit Date:
2009-02-17
Status:
Resolved
Updated Date:
2010-05-11
Project Name:
JDK
Resolved Date:
2009-03-07
Component:
core-libs
OS:
generic
Sub-Component:
java.math
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u14
Fixed Versions:
6u14

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
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.

                                    

Comments
EVALUATION

The root cause of the NullPointerException in the test case is that we try to refer intVal before actually calling inflate(). The fix is to add inflate() call.
                                     
2009-02-17



Hardware and Software, Engineered to Work Together