Skip to content

Don't catch OutOfMemoryError #1699

@Marcono1234

Description

@Marcono1234

Gson currently catches OutOfMemoryErrors at two places and wraps them inside JsonParseException:

} catch (OutOfMemoryError e) {
throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e);

} 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions