Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-120

JSONP spec compliance: JsonNumber.int/longValueExact() does not throw ArithmeticException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.0.0
    • 1.1.2
    • 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--

      Attachments

        Activity

          People

            romain.manni-bucau Romain Manni-Bucau
            SvetlinZarev Svetlin Zarev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: