Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ public long nextLong() throws IOException {
long result;
try {
result = primitive.getAsLong();
if (token == JsonToken.NUMBER && result != primitive.getAsDouble()) {
// Mirror JsonReader: reject numbers that cannot be exactly represented as a long
throw new NumberFormatException("Expected a long but was " + primitive.getAsString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably have to move this out of the try-catch(NumberFormatException), otherwise this exception is redundantly wrapped.

(same for nextInt below as well)

}
} catch (NumberFormatException e) {
throw numberFormatException("Expected a long but was " + primitive.getAsString(), e);
}
Expand All @@ -298,6 +302,10 @@ public int nextInt() throws IOException {
int result;
try {
result = primitive.getAsInt();
if (token == JsonToken.NUMBER && result != primitive.getAsDouble()) {
// Mirror JsonReader: reject numbers that cannot be exactly represented as an int
throw new NumberFormatException("Expected an int but was " + primitive.getAsString());
}
} catch (NumberFormatException e) {
throw numberFormatException("Expected an int but was " + primitive.getAsString(), e);
}
Expand Down