-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
Description
Gson currently catches OutOfMemoryErrors at two places and wraps them inside JsonParseException:
gson/gson/src/main/java/com/google/gson/JsonParser.java
Lines 88 to 89 in c5a3f21
| } catch (OutOfMemoryError e) { | |
| throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); |
gson/gson/src/main/java/com/google/gson/JsonStreamParser.java
Lines 90 to 91 in b75e1bb
| } catch (OutOfMemoryError e) { | |
| throw new JsonParseException("Failed parsing JSON source to Json", e); |
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 #1912 (comment). However, it appears OutOfMemoryError is not caught consistently everywhere.