Skip to content

Gson.getAdapter((TypeToken) null) throws exception #1831

@Marcono1234

Description

@Marcono1234

The Gson class has logic for handling null arguments for getAdapter(TypeToken), see:

TypeAdapter<?> cached = typeTokenCache.get(type == null ? NULL_KEY_SURROGATE : type);

However, it appears the pull request which tried to keep the support for null arguments also broke it due to commit 31dcfa3 because it does not reassign a non-null value to the type argument anymore which later on in the method causes a NullPointerException.

However that was 4 years ago and it appears support for null arguments might not have been used much (if at all; I did not find existing issues about this here on GitHub). Therefore maybe it would be better instead of fixing this issue to simply remove null handling for getAdapter(TypeToken) completely and to throw an exception on purpose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions