You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Svetlin Zarev (JIRA)" <ji...@apache.org> on 2017/06/05 07:19:04 UTC
[jira] [Created] (JOHNZON-120) JSONP spec compliance:
JsonNumber.int/longValueExact() does not throw ArithmeticException
Svetlin Zarev created JOHNZON-120:
-------------------------------------
Summary: JSONP spec compliance: JsonNumber.int/longValueExact() does not throw ArithmeticException
Key: JOHNZON-120
URL: https://issues.apache.org/jira/browse/JOHNZON-120
Project: Johnzon
Issue Type: Bug
Affects Versions: 1.0.0
Reporter: Svetlin Zarev
According to the JSONP spec, if the json number has non zero fractional part, intValueExact() & longValueExcat() must throw Arithmetic exception: [1], [2]
{code}
* java.lang.ArithmeticException - if the number has a nonzero fractional part or if it does not fit in an int
* java.lang.ArithmeticException - if the number has a non-zero fractional part or if it does not fit in a long
{code}
Sample application to reproduce the issue:
{code}
public final class Main {
public static void main(String[] args) {
JsonArray array = Json.createArrayBuilder()
.add(12345.6489)
.build();
boolean success = false;
try {
int value = array
.getJsonNumber(0)
.intValueExact();
} catch (ArithmeticException ex) {
success = true;
}
System.out.println("Caught expected exception: " + success);
}
{code}
[1] http://docs.oracle.com/javaee/7/api/javax/json/JsonNumber.html#intValueExact--
[2] http://docs.oracle.com/javaee/7/api/javax/json/JsonNumber.html#longValueExact--
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)