Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.0.0
-
None
-
None
Description
According to the JSONP spec, if the json number has non zero fractional part, intValueExact() & longValueExcat() must throw Arithmetic exception: [1], [2]
* 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
Sample application to reproduce the issue:
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); }
[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--