Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonReader throws NumberFormatException which does not contain location info #1564

Open
jdlib opened this issue Aug 12, 2019 · 0 comments · May be fixed by #1764
Open

JsonReader throws NumberFormatException which does not contain location info #1564

jdlib opened this issue Aug 12, 2019 · 0 comments · May be fixed by #1764
Labels

Comments

@jdlib
Copy link

jdlib commented Aug 12, 2019

The message of exceptions thrown by JsonReader usually contains location information including the current path. This is really helpful to locate the error in the input JSON.

Example: java.lang.IllegalStateException: Expected an int but was BOOLEAN at line 7 column 10 path $.x.y

Now JsonReader.nextInt(), .nextLong(), .nextDouble() may throw exceptions that contain no such location information. The exception is thrown in the lines
double asDouble = Double.parseDouble(peekedString); // don't catch this NumberFormatException.

How to provoke that specific exception:
Model: public class Model { int x; }
and then call new GsonBuilder().create().fromJson("{ x: ''}", Model.class}

The exception message will be: java.lang.NumberFormatException: empty String, containg no location information.
The exception itself was thrown by Double and JsonReader just passed it along.

Imho JsonReader should catch the exception from Double.parseDouble and add location information to a rethrown copy.

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

Successfully merging a pull request may close this issue.

2 participants