JDK-6812880 : AssertionError in BigDecimal.remainder
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 6u14
  • Priority: P1
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-03-04
  • Updated: 2014-02-27
  • Resolved: 2009-03-28
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
6u14 b04Fixed
Related Reports
Relates :  
Relates :  
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
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

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

EVALUATION See Comments.
2009-03-05