You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
incompatible types: Optional<@Nullable SomeType> cannot be converted to Optional<SomeType> #1594
NullAway 0.13.6 is inferring Optionals of @Nullable types, whereas NullAway 0.13.4 had correctly derived them as non-null.
We have encountered this in a large Spring Boot / gradle project, and upgrading NullAway introduces hundreds of false positives of this kind. We are using JSpecify annotations and running in JSpecify mode.
The examples we have seen, so far, are generally from Stream terminal operations.
Sample warning message
warning: [NullAway] incompatible types: Optional<@Nullable Double> cannot be converted to Optional<Double>
.reduce(Double::sum);
^
(see http://t.uber.com/nullaway )
1 error
1 warning
Minimal repro
packageexample.nullaway;
importjava.util.Arrays;
importjava.util.Objects;
importjava.util.Optional;
importorg.jspecify.annotations.Nullable;
publicclassNullAwayExample {
// Both NullAway 0.13.4 and 0.13.6 accept this method with no violations.publicstaticOptional<Double> sumNumbersAsDoubles(@NullableNumber... numbers) {
returnArrays.stream(numbers)
.filter(Objects::nonNull)
.map(Number::doubleValue)
.reduce(Double::sum);
}
// NullAway 0.13.4 accepts this method with no violations.//// NullAway 0.13.6 does not accept this method, and reports:// ```// warning: [NullAway] incompatible types: Optional<@Nullable Double> cannot be converted to Optional<Double>// .reduce(Double::sum);// ^// (see http://t.uber.com/nullaway )// 1 error// 1 warning// ```publicstaticOptional<Double> sumDoubles(@NullableDouble... doubles) {
returnArrays.stream(doubles)
.filter(Objects::nonNull)
.reduce(Double::sum);
}
// Both NullAway 0.13.4 and 0.13.6 accept this method with no violations.publicstaticOptional<Double> sumDoublesWithExplicitMap(@NullableDouble... doubles) {
returnArrays.stream(doubles)
.filter(Objects::nonNull)
.map(Objects::requireNonNull)
.reduce(Double::sum);
}
}
You only fixed Streams, but this issue was also about Optional. I commented a reproducer.
I don't think this issue should be marked fixed until Optional filtering is also fixed.
Activity
lbenedetto commentedon Jun 8, 2026
Also happens for very simple cases like this one:
msridhar commentedon Jun 8, 2026
Thank you for all the examples. I think this is related to #1578, but also to library models for
Optional. Will prioritize fixing this one.Add support for filtering null objects from streams (apache#1597)
lbenedetto commentedon Jun 18, 2026
You only fixed Streams, but this issue was also about Optional. I commented a reproducer.
I don't think this issue should be marked fixed until Optional filtering is also fixed.
msridhar commentedon Jun 18, 2026
@lbenedetto I think your issue is a different bug than what was fixed here. Let's track in #1611.