google / google/gson

Long upper limit value

Open
#1,727 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

Use Gson
```
Gson gson = new Gson();
Long a = gson.fromJson("9223372036854775808", Long.class);
System.out.println(a);

=> 9223372036854775807
```

Use JsonPrimitive
```
var jp = new JsonPrimitive("9223372036854775808");
Long b = jp.getAsLong();
System.out.println(b);

=> java.lang.NumberFormatException: For input string: "9223372036854775808"
```

Use Long.valueOf
```
Long c = Long.valueOf("9223372036854775808");
System.out.println(c);

=> java.lang.NumberFormatException: For input string: "9223372036854775808"
```

Why is there no error in Gson?
Is this a bug? Or is it a specification?
I want an error to occur.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.