RFR: JDK-8211161: java.lang.ArithmeticException: divide by zero from java.text.DecimalFormat.format()

Nasser Ebrahim enasser at in.ibm.com
Wed Sep 26 17:44:25 UTC 2018

Hi Joe,

Thank you for your review comments. 

I agree with you that the specification says that "The floating-point 
operations of the Java Virtual Machine do not throw exceptions, trap, or 
otherwise signal the IEEE 754 exceptional conditions of invalid operation, 
division by zero, overflow, underflow, or inexact." as per the JVM 

I noticed that the SIGFPE is consumed and no exception is thrown when 
SIGFPE is enabled before create JVM. Hence, there is an inconsistency in 
the hotspot behavior when the SIGFPE is enabled before and after create 
JVM. If the trap is enabled before create JVM, it just catch the exception 
and continue where as if the trap is enabled after create JVM, then it 
result in the ArithmeticException. Hence, the JVM behavior needs to be 
fixed to make the behavior consistent. 

Still, I feel it makes more sense to check the sign bit to decide a number 
is negative or positive rather than divide-by-zro to make infinity and 
compare with zero. If you agree with my view, a separate bug can be opened 
to fix the JVM inconsistent behavior. Otherwise, we can change the 
component of this bug. Please comment.

Thank you, 
Nasser Ebrahim

From:   joe darcy <joe.darcy at oracle.com>
To:     Nasser Ebrahim <enasser at in.ibm.com>, core-libs-dev Libs 
<core-libs-dev at openjdk.java.net>
Date:   09/26/2018 10:29 PM
Subject:        Re: RFR: JDK-8211161: java.lang.ArithmeticException: 
divide by zero from java.text.DecimalFormat.format()


It may be reasonable to replace a divide by zero with check for a 
floating-point -0.0 with a bit-level check, but the stated motivation is 
not reasonable.

The Java platform requires that floating-point divide by zero return an 
infinity (or NaN as the case may be) and it is *incorrect* and 
non-conformant to throw an ArithmeticException in that case. Such 
behavior violates the language the JVM specs.



On 9/26/2018 9:33 AM, Nasser Ebrahim wrote:
> Hello,
> In java.text.DecimalFormat.format(), there is a validation to check
> whether a number is negative zero or not and for that divide by zero is
> used to check for negative infinity which caused the ArithmeticException
> when SIGFPE is enabled in the system. Andrew has opened a bug on my
> behalf. Thank you Andrew.
> The corresponding bug is 
> The webrev and stand alone test case is uploaded to
> The recreate step is documented in the bug description.
> I have tested the fix with the test cases of the following bugs and
> confirm that it is working.



> I did not add any new jtreg test for the current issue as it is not
> functional. Hope that is fine.
> Kindly request you to review and comment.
> Thank you,
> Nasser Ebrahim

More information about the core-libs-dev mailing list