JDK-6850606 : Regression from JDK 1.6.0_12
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 6u14
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: x86
  • Submitted: 2009-06-12
  • Updated: 2011-02-16
  • Resolved: 2010-11-30
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.
JDK 6 JDK 7 Other
6u18Fixed 7 b64Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
C:\JAVA\jdk1.6.0_14_32bit\bin>java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP Pro 64 bit, SP2

A DESCRIPTION OF THE PROBLEM :
The following code runs fine under JDK 1.6.0_12, but fails with a NullPointerException in JDK 1.6.0_14

    public void testCanApproximateLogWithInputTerms() {

        BigDecimal x = BigDecimal.valueOf(8L, 1);
        BigDecimal xPower = BigDecimal.valueOf(-1L);

        for (int i = 0; i < 100; i++) {
            xPower = xPower.multiply(x);
        }
    }


java.lang.NullPointerException
	at java.math.BigDecimal.multiply(BigDecimal.java:1312)
	at com.rtrms.math.EulersSumTest.testCanApproximateLogWithInputTerms(EulersSumTest.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Excecute the test code listed above

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should run without error
ACTUAL -
java.lang.NullPointerException
	at java.math.BigDecimal.multiply(BigDecimal.java:1312)
	at com.rtrms.math.EulersSumTest.testCanApproximateLogWithInputTerms(EulersSumTest.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at java.math.BigDecimal.multiply(BigDecimal.java:1312)
	at com.rtrms.math.EulersSumTest.testCanApproximateLogWithInputTerms(EulersSumTest.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    public void testCanApproximateLogWithInputTerms() {

        BigDecimal x = BigDecimal.valueOf(8L, 1);
        BigDecimal xPower = BigDecimal.valueOf(-1L);

        for (int i = 0; i < 100; i++) {
            xPower = xPower.multiply(x);
        }
    }


---------- END SOURCE ----------

Release Regression From : 6u12
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION The root cause is that when the product is equals to INFLATED, we construct the returned BigDecimal for multiply explicity and set the intVal to null which is wrong. The correct way is to use BigDecimal.valueOf(product, productScale) since valueOf will take care of the INFLATED case.
18-06-2009