-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Malformed Unicode escape sequence causes NumberFormatException
instead of MalformedJsonException
#2334
Labels
Comments
I agree. It's weird to throw |
MaicolAntali
added a commit
to MaicolAntali/gson
that referenced
this issue
Mar 6, 2023
This commit replaces the `NumberFormatException` with `MalformedJsonException` in the `JsonReader#readEscapeCharacter()` and also fixes the tests.
eamonnmcmanus
pushed a commit
that referenced
this issue
Mar 6, 2023
eamonnmcmanus
pushed a commit
that referenced
this issue
May 31, 2023
tibor-universe
pushed a commit
to getuniverse/gson
that referenced
this issue
Sep 14, 2024
* Fix google#2334 This commit replaces the `NumberFormatException` with `MalformedJsonException` in the `JsonReader#readEscapeCharacter()` and also fixes the tests. * Removes white-space
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gson version
2.10.1
Description
JsonReader
throws aNumberFormatException
instead of aMalformedJsonException
when it encounters a malformed Unicode escape sequence in the JSON data.This actually works as designed:
gson/gson/src/main/java/com/google/gson/stream/JsonReader.java
Lines 1590 to 1591 in 1998373
However, it is questionable whether that design is really a good choice because a
MalformedJsonException
seems to fit better here, especially since other malformed escape sequences do cause aMalformedJsonException
.Note that
NumberFormatException
being thrown is apparently not publicly documented, so changing this should be rather safe to do.Expected behavior
A
MalformedJsonException
is thrown for malformed Unicode escape sequences.Actual behavior
A
NumberFormatException
is thrown.Reproduction steps
The text was updated successfully, but these errors were encountered: