United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6850606 Regression from JDK 1.6.0_12
JDK-6850606 : Regression from JDK 1.6.0_12

Details
Type:
Bug
Submit Date:
2009-06-12
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2010-11-30
Component:
core-libs
OS:
solaris_8
Sub-Component:
java.math
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u14
Fixed Versions:

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

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.
                                     
2009-06-18



Hardware and Software, Engineered to Work Together