discomarathon / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Parser fails on "1E+5" #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
* What steps will reproduce the problem?

Try executing either of these lines:
    Double x = new Gson().fromJson("1E+5", Double.class);
    BigDecimal y = new Gson().fromJson("1E+5", BigDecimal.class);

* What is the expected output? What do you see instead?

The expected result is a Double or BigDecimal containing the value 100000.
The actual behaviour is a NumberFormatException thrown from within the
java.math.BigDecimal constructor.  The key line is in the method
JsonParser.JsonNumber():

    n = new java.math.BigDecimal(intpart + fracpart + exppart);

At this point, fracpart is null because there is no decimal point in
"1E+5", and so the string addition produces "1nullE+5".  Is this a bug
in JsonParser.jj or perhaps even in the parser generator?

* What version of the product are you using? On what operating system?

I'm using Gson release 1.2.3 on Linux.

Original issue reported on code.google.com by p...@zesty.ca on 18 Nov 2008 at 12:39

GoogleCodeExporter commented 9 years ago

Original comment by joel.leitch@gmail.com on 18 Nov 2008 at 7:55

GoogleCodeExporter commented 9 years ago
Fixed in r304

Original comment by joel.leitch@gmail.com on 18 Nov 2008 at 7:56