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

Fix missing null checks in DataProviderRegistrator #3522

Merged
merged 1 commit into from
Oct 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ protected Value<E> constructValue(final H dataHolder, final E element) {

@Override
protected Optional<E> getFrom(final H dataHolder) {
if (registration.get == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any time where this is actually going to be null? I can't imagine there is a use case for a write-only key within Sponge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, it is, but who knows, maybe someday it will be. Given that the get field is declared with @Nullable annotation, I think the check should be.

return Optional.empty();
}
if (this.isBooleanKey) {
return (Optional<E>) OptBool.of((Boolean) registration.get.apply(dataHolder));
}
Expand Down Expand Up @@ -487,6 +490,9 @@ protected Value<E> constructValue(final H dataHolder, final E element) {

@Override
protected Optional<E> getFrom(final H dataHolder) {
if (registration.get == null) {
return Optional.empty();
}
if (this.isBooleanKey) {
return (Optional<E>) OptBool.of((Boolean) registration.get.apply(dataHolder));
}
Expand All @@ -495,6 +501,9 @@ protected Optional<E> getFrom(final H dataHolder) {

@Override
protected Optional<H> set(final H dataHolder, final E value) {
if (registration.set == null) {
return Optional.empty();
}
return Optional.ofNullable(registration.set.apply(dataHolder, value));
}

Expand Down