JDK-6806261 : BigDecimal.longValueExact() method throws NullPointerException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 6u14
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-02-17
  • Updated: 2010-05-11
  • Resolved: 2009-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6u14 b03Fixed 7Fixed
Related Reports
Relates :  
Relates :  
BigDecimal.longValueExact() method throws NullpointerException with 6u14-b01 build.
Following testcase could be used to reproduce the issue.


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 ");



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)


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.

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.