johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Svetlin Zarev (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JOHNZON-120) JSONP spec compliance: JsonNumber.int/longValueExact() does not throw ArithmeticException
Date Mon, 05 Jun 2017 07:19:04 GMT
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)

Mime
View raw message