-
Notifications
You must be signed in to change notification settings - Fork 331
False-positive warning on Objects.requireNonNullElse #1493
Copy link
Copy link
Open
Labels
Description
In my project I want to use NullAway Gradle plugin with warnOnGenericInferenceFailure feature enabled, but I am getting warnings on Objects.requireNonNullElse whenever I use it as return value of method. For example, this method:
public String nonNullElse(@Nullable String nullableString, String defaultValue) {
return Objects.requireNonNullElse(nullableString, defaultValue);
}
would result in a warning:
[NullAway] Failed to infer type argument nullability for call Objects.requireNonNullElse(nullableString, defaultValue): Contradictory nullability for T: NONNULL vs. NULLABLE
The only workaround for now is to write something like this:
public String nonNullElse(@Nullable String nullableString, String defaultValue) {
return Objects.<String>requireNonNullElse(nullableString, defaultValue);
}
which is redundant as it should be obvious that Objects.requireNonNullElse never returns null in this situation
Reactions are currently unavailable