Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6819773
Votes 0
Synopsis BigDecimal.divide(BigDecimal,int,int) throws ArrayIndexOutofBoundsException under some circumstances
Category java:classes_math
Reported Against b01
Release Fixed 6u14(b04)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 6820130
Submit Date 19-MAR-2009
Description
java.math.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode) 
throws unspecified ArrayIndexOutOfBoundsException
when roundingMode equals BigDecimal.ROUND_HALF_EVEN


How to reproduce:
-----------------

To reproduce this bug run the following BigDecimalTest

NOTE: the code is copied from  customer  license Harmony test.

-------------------BigDecimalTest.java--------
import java.math.*;

import java.math.*;

public class BigDecimalTest {
    public static void main(String[] args) {
        String dec1 = "-37361671119238118911893939591735";
        int scale1 = 10;
        String dec2 = "74723342238476237823787879183470";
        int scale2 = 15;
        int resScale = -5;
        BigDecimal decN1 = new BigDecimal(new BigInteger(dec1), scale1);
        BigDecimal decN2 = new BigDecimal(new BigInteger(dec2), scale2);
        BigDecimal result;
        int round = -1;
        String sRound = "";
        try {
            round = BigDecimal.ROUND_HALF_UP;
            sRound = "BigDecimal.ROUND_HALF_UP";
            result = decN1.divide(decN2, resScale, round);
            System.out.println("divide with " + sRound + " passsed. result="
                + result);

            round = BigDecimal.ROUND_HALF_DOWN;
            sRound = "BigDecimal.ROUND_HALF_DOWN";
            result = decN1.divide(decN2, resScale, round);
            System.out.println("divide with " + sRound + " passsed. result="
                + result);

            round = BigDecimal.ROUND_HALF_EVEN;
            sRound = "BigDecimal.ROUND_HALF_EVEN";
            result = decN1.divide(decN2, resScale, round);
            System.out.println("divide with " + sRound + " passsed. result="
                + result);

        } catch (Throwable e) {
            System.out.println("divide with " + sRound + " failed");
            System.out.println("Unexpected exception was thrown. " + round);
            e.printStackTrace(System.out);
        }
    }
}
------------

Diagnostics/output:
-------------------

Output on 6u14 b03 ia32:

java version "1.6.0_14-ea"
Java(TM) SE Runtime Environment (build 1.6.0_14-ea-b03)
Java HotSpot(TM) Client VM (build 14.0-b12, mixed mode, sharing)

divide with BigDecimal.ROUND_HALF_UP passsed. result=-1E+5
divide with BigDecimal.ROUND_HALF_DOWN passsed. result=0E+5
divide with BigDecimal.ROUND_HALF_EVEN failed
Unexpected exception was thrown. 6
java.lang.ArrayIndexOutOfBoundsException: -1
        at java.math.MutableBigInteger.isOdd(Unknown Source)
        at java.math.BigDecimal.divideAndRound(Unknown Source)
        at java.math.BigDecimal.divide(Unknown Source)
        at BigDecimalTest.main(BigDecimalTest.java:30)
Posted Date : 2009-03-19 19:11:00.0
Work Around
N/A
Evaluation
See comments section.
Posted Date : 2009-03-19 19:11:00.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang