Skip to content
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

Add null checks for GsonBuilder methods #2179

Merged

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Aug 20, 2022

Currently most GsonBuilder methods do not check for null. This can lead to NullPointerExceptions being thrown at completely unrelated places when the created Gson instance is used. (Might be the reason for #1578.)

Have not added a null check to setDateFormat(String pattern) because it looks like the pattern can be null (at least that is the default value).

Also resolves #1528

Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks great.

Separately, perhaps we should get rid of $Gson$Preconditions.checkNotNull entirely and replace it with Objects.requireNonNull now that we are require Java 7.

@eamonnmcmanus eamonnmcmanus merged commit b84b221 into google:master Aug 20, 2022
@Marcono1234 Marcono1234 deleted the marcono1234/GsonBuilder-null-checks branch August 20, 2022 23:55
@Marcono1234
Copy link
Collaborator Author

Separately, perhaps we should get rid of $Gson$Preconditions.checkNotNull entirely and replace it with Objects.requireNonNull now that we are require Java 7.

Good point! Have created #2180 for that. (I hope you weren't working on this as well already.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Describe that GsonBuilder setFieldNamingPolicy and setFieldNamingStrategy are the same
2 participants