Don't catch OutOfMemoryError
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
Gson currently catches `OutOfMemoryError`s at two places and wraps them inside `JsonParseException`:
https://github.com/google/gson/blob/c5a3f21fbad3828deba1deb88168e1f76829f807/gson/src/main/java/com/google/gson/JsonParser.java#L88-L89
https://github.com/google/gson/blob/b75e1bbc7915f409ba0254fcc92c71ed6798e69b/gson/src/main/java/com/google/gson/JsonStreamParser.java#L90-L91
This is bad practice because Gson is not necessarily the cause for this error and wrapping it inside an `Exception` subclass prevents the caller from noticing the `OutOfMemoryError` until later.
Edit: Catching `OutOfMemoryError` _might_ be desired to protect about malicious JSON data, see also https://github.com/google/gson/pull/1912#issuecomment-1130767871. However, it appears `OutOfMemoryError` is not caught consistently everywhere.
Contributor guide
Assessment
This issue has not been assessed yet.