-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Update to NullAway 0.14.0 and fix new warnings #37188
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ public ConvertingComparator(Comparator<T> comparator, Converter<S, T> converter) | |
| * @param conversionService the conversion service | ||
| * @param targetType the target type | ||
| */ | ||
| @SuppressWarnings("NullAway") // Retain support for comparators that handle a null conversion result | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is Codex's explanation for this warning suppression. I read through it and it makes sense to me, but I'm not an expert on this code. I'm not sure what is the best fix (that is not a suppression). The suppression covers a real mismatch between the legacy runtime behavior and the declared generic types. The constructor adapts a public ConvertingComparator(
Comparator<T> comparator,
ConversionService conversionService,
Class<? extends T> targetType) {
this(comparator,
new ConversionServiceConverter<>(conversionService, targetType));
}The delegated constructor expects: ConvertingComparator(Comparator<T>, Converter<S, T>)But <T> @Nullable T convert(@Nullable Object source, Class<T> targetType);Consequently, the adapter is: Converter<S, @Nullable T>NullAway correctly observes that this cannot safely become T converted = this.converter.convert(source);
return this.comparator.compare(converted1, converted2);If conversion returns
The existing API allows both possibilities and leaves responsibility with the supplied comparator. That relationship is not accurately represented by the constructor’s The comment therefore means:
For example, adding this would satisfy NullAway: return Objects.requireNonNull(
this.conversionService.convert(source, this.targetType));But it would change behavior by rejecting null before a null-aware comparator could process it. Accurately modeling this would require a larger API redesign, likely requiring this constructor to produce a Thus, this suppression is:
|
||
| public ConvertingComparator( | ||
| Comparator<T> comparator, ConversionService conversionService, Class<? extends T> targetType) { | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately, we could wait for a new nullability plugin release that defaults to 0.14.0. The other changes would remain valid.