United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6812880 : AssertionError in BigDecimal.remainder

Details
Type:
Bug
Submit Date:
2009-03-04
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2009-03-28
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.math
CPU:
x86
Priority:
P1
Resolution:
Fixed
Affected Versions:
6u14
Fixed Versions:
6u14 (b04)

Related Reports
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_14-ea"
Java(TM) SE Runtime Environment (build 1.6.0_14-ea-b01)
OpenJDK Client VM (build 14.0-b10, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
BigDecimal.remainder throws Exception

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See test case

ACTUAL -
AssertionError

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.AssertionError: this MutableBigInteger can't be fit into long
	at java.math.MutableBigInteger.toLong(MutableBigInteger.java:129)
	at java.math.MutableBigInteger.divide(MutableBigInteger.java:930)
	at java.math.BigDecimal.divideAndRound(BigDecimal.java:1416)
	at java.math.BigDecimal.setScale(BigDecimal.java:2377)
	at java.math.BigDecimal.setScale(BigDecimal.java:2310)
	at java.math.BigDecimal.divideToIntegralValue(BigDecimal.java:1710)
	at java.math.BigDecimal.divideAndRemainder(BigDecimal.java:1865)
	at java.math.BigDecimal.remainder(BigDecimal.java:1807)
	at it.prodata.gest.test.Test.main(Test.java:79)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
	public static void main(String s[]) {
		BigDecimal bd1 = new BigDecimal("200000000000000000000000000000");
		BigDecimal bd2 = BigDecimal.valueOf(97);
		System.out.println(bd1.remainder(bd2));
	}
}

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

See Comments.
                                     
2009-03-05
EVALUATION

This appears to a bug in the assertion. It should be asserting that the number of ints in the value array is 2 or less.
                                     
2009-03-06
SUGGESTED FIX

------- MutableBigInteger.java -------
*** /tmp/sccs.ZBaiqu    Sat Mar  7 10:07:13 2009
--- MutableBigInteger.java      Fri Mar  6 21:48:57 2009
***************
*** 123,132 ****
       * sure this MutableBigInteger can be fit into long.
       */
      private long toLong() {
          if (intLen == 0)
              return 0;
          long d = value[offset] & LONG_MASK;
-         assert (intLen > 2) : "this MutableBigInteger can't be fit into long";
          return (intLen == 2) ?
              d << 32 | (value[offset + 1] & LONG_MASK) : d;
      }
--- 123,132 ----
       * sure this MutableBigInteger can be fit into long.
       */
      private long toLong() {
+         assert (intLen <= 2) : "this MutableBigInteger can't be fit into long";
          if (intLen == 0)
              return 0;
          long d = value[offset] & LONG_MASK;
          return (intLen == 2) ?
              d << 32 | (value[offset + 1] & LONG_MASK) : d;
      }
                                     
2009-03-07



Hardware and Software, Engineered to Work Together