Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

It shall raise exception when double type value is out of the scope #894

Closed
greenlaw110 opened this issue Nov 13, 2016 · 2 comments
Closed
Milestone

Comments

@greenlaw110
Copy link

This is a sub issue of #868 which fixed the value overflow issue on Float, but not on Double

@wenshao wenshao added this to the 1.2.29 milestone Mar 10, 2017
@greenlaw110
Copy link
Author

Given the following program:

  public static void foo() throws Exception {
        String str = String.valueOf(Double.MAX_VALUE);
        short sh = JSON.parseObject(str, short.class);
        System.out.println(sh);
    }

FastJson will return 0 when the value is out of the scope of short type. Suppose it shall raise an exception in such case.

@greenlaw110
Copy link
Author

There is still an issue:

public static void main(String[] args) throws Exception {
    BigDecimal dec = BigDecimal.valueOf(Double.MAX_VALUE);
    dec = dec.add(dec);
    String str = dec.toString();
    double dbl = JSON.parseObject(str, double.class);
    System.out.println(dbl);
}

The above code print out Infinity instead of raising an exception, something like:

throw new JSONException("double overflow : " + val);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants