harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Wu" <wuyue...@gmail.com>
Subject Re: [classlib][math] one more non-bug diff ? ([jira] (HARMONY-1499) BigDecimal((BigInteger)null, MathContext) throws NPE on Harmony and ArithmeticException on RI
Date Wed, 20 Sep 2006 08:07:39 GMT
RI disobeys spec because all constructors of BigDecimal do not throw any NPE
when encounter a null parameter.
I incline to follow spec and mark this issue as an non-bug difference.

On 9/20/06, Vladimir Ivanov <ivavladimir@gmail.com> wrote:
>
> As pointed in the HARMONY-1499 constructors BigDecimal((BigInteger)null,
> new
> MathContext("precision=14 roundingMode=UNNECESSARY")) and
> BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) throws NPE
> on
> Harmony and ArithmeticException on RI.
>
> The spec requires NPE and BEA throws NPE in this case also as Harmony. I
> suggest following the spec in this case.
> Any objection?
>
> thanks, Vladimir
>
>
> ---------- Forwarded message ----------
> From: Vladimir Ivanov (JIRA) <jira@apache.org>
> Date: Sep 20, 2006 2:05 PM
> Subject: [jira] Created: (HARMONY-1499) [classlib][math]
> BigDecimal((BigInteger)null, MathContext) throws NPE on Harmony and
> ArithmeticException on RI
> To: ivavladimir@gmail.com
>
> [classlib][math] BigDecimal((BigInteger)null, MathContext) throws NPE on
> Harmony and ArithmeticException on RI
>
> --------------------------------------------------------------------------------------------------------------
>
>                Key: HARMONY-1499
>                URL: http://issues.apache.org/jira/browse/HARMONY-1499
>            Project: Harmony
>         Issue Type: Bug
>         Components: Classlib
>           Reporter: Vladimir Ivanov
>           Priority: Minor
>
>
> The constructors BigDecimal((BigInteger)null, new
> MathContext("precision=14
> roundingMode=UNNECESSARY")) and
> BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) throws NPE
> on
> Harmony and ArithmeticException on RI.
> The spec says for BigDecimal class: "All methods and constructors for this
> class throw NullPointerException when passed a null object reference for
> any
> input parameter" and for the thes constructors: "Throws:
> ArithmeticException
> - if the result is inexact but the rounding mode is UNNECESSARY."
>
> Seems, that the RI does not check input for 'null' values. While BEA
> throws
> NPE in this case and RI behavior contradicts to the spec it may be
> 'non-bug
> diff'.
>
> ================== test.java =====================
> import java.math.*;
>
> public class test {
>   public static void main(String[] args) {
>       try {
>            System.out.println("res = " + new BigDecimal((BigInteger)null,
> new MathContext("precision=14 roundingMode=DOWN")));
>       } catch (Exception e) {
>            e.printStackTrace();
>       }
>       try {
>            System.out.println("res = " + new BigDecimal((BigInteger)null,
> new MathContext("precision=14 roundingMode=UNNECESSARY")));
>       } catch (Exception e) {
>            e.printStackTrace();
>       }
>       try {
>            System.out.println("res = " + new BigDecimal((BigInteger)null,
> 1, new MathContext("precision=14 roundingMode=UNNECESSARY")));
>       } catch (Exception e) {
>            e.printStackTrace();
>       }
>   }
> }
> ==============================================
>
> Output:
> ---------------------------------------------------
> C:\tmp\tmp17>C:\jdk1.5.0_08\bin\java.exe -cp . -showversion test
> java version "1.5.0_08"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
> Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
>
> res = -9.2233720368547E+18
> java.lang.ArithmeticException: Rounding necessary
>       at java.math.BigDecimal.divide(BigDecimal.java:1346)
>       at java.math.BigDecimal.dropDigits(BigDecimal.java:3463)
>       at java.math.BigDecimal.doRound(BigDecimal.java:3433)
>       at java.math.BigDecimal.roundThis(BigDecimal.java:3399)
>       at java.math.BigDecimal.<init>(BigDecimal.java:811)
>       at test.main(test.java:11)
> java.lang.ArithmeticException: Rounding necessary
>       at java.math.BigDecimal.divide(BigDecimal.java:1346)
>       at java.math.BigDecimal.dropDigits(BigDecimal.java:3463)
>       at java.math.BigDecimal.doRound(BigDecimal.java:3433)
>       at java.math.BigDecimal.roundThis(BigDecimal.java:3399)
>       at java.math.BigDecimal.<init>(BigDecimal.java:851)
>       at test.main(test.java:16)
>
> ---------------------------------------------------
> C:\tmp\tmp17>C:\jrockit-jdk1.5.0-windows-ia32\bin\java.exe -cp .
> -showversion test
> java version "1.5.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
> BEA WebLogic JRockit(R) (build dra-38972-20041208-2001-win-ia32,
> R25.0.0-75,
> GC: System optimized over throughput (initial strategy singleparpar))
>
> java.lang.NullPointerException
>       at java.math.BigDecimal.doRound(BigDecimal.java:3066)
>       at java.math.BigDecimal.roundThis(BigDecimal.java:3042)
>       at java.math.BigDecimal.<init>(BigDecimal.java:751)
>       at test.main(test.java:6)
> java.lang.NullPointerException
>       at java.math.BigDecimal.doRound(BigDecimal.java:3066)
>       at java.math.BigDecimal.roundThis(BigDecimal.java:3042)
>       at java.math.BigDecimal.<init>(BigDecimal.java:751)
>       at test.main(test.java:11)
> java.lang.NullPointerException
>       at java.math.BigDecimal.doRound(BigDecimal.java:3066)
>       at java.math.BigDecimal.roundThis(BigDecimal.java:3042)
>       at java.math.BigDecimal.<init>(BigDecimal.java:788)
>       at test.main(test.java:16)
>
> ---------------------------------------------------
> C:\tmp\tmp17>C:\harmony\classlib1.5\deploy\jdk\jre\bin\java.exe -cp . test
> java.lang.NullPointerException
>       at java.math.BigDecimal.<init>(BigDecimal.java:384)
>       at java.math.BigDecimal.<init>(BigDecimal.java:372)
>       at java.math.BigDecimal.<init>(BigDecimal.java:377)
>       at test.main(test.java:6)
> java.lang.NullPointerException
>       at java.math.BigDecimal.<init>(BigDecimal.java:384)
>       at java.math.BigDecimal.<init>(BigDecimal.java:372)
>       at java.math.BigDecimal.<init>(BigDecimal.java:377)
>       at test.main(test.java:11)
> java.lang.NullPointerException
>       at java.math.BigDecimal.<init>(BigDecimal.java:384)
>       at java.math.BigDecimal.<init>(BigDecimal.java:392)
>       at test.main(test.java:16)
>
> ---------------------------------------------------
>
> C:\tmp\tmp17>C:\harmony\drlvm1.5\build\win_ia32_msvc_debug\deploy\jre\bin\java
> -Dvm.assert_dialog=false -cp . -showversion test
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
> Foundation or its licensors, as applicable.
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = r448020, (Sep 20 2006), Windows/ia32/msvc 1310, debug build
> http://incubator.apache.org/harmony
> java.lang.NullPointerException
>       at test.main(test.java:6)
> java.lang.NullPointerException
>       at test.main(test.java:11)
> java.lang.NullPointerException
>       at test.main(test.java:16)
>
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
> http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message