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
Give the conditional-expression, method-reference, and override reporters the marked generic mismatch message #2207
#1828 reports a generic nullability mismatch at an assignment, an argument, or a return as a marked diff of the two types. The same mismatch reached through a conditional expression, a method reference, or an override still gets the old message, which prints both types in full and no position:
@NullMarkedclassTest {
voidf(booleanb, List<?> l, List<Object> o) {
Collection<? extendsObject> c1 = l; // marked diff, with noteCollection<? extendsObject> c2 = b ? l : o; // old message
}
}
Conditional expression must have type Collection<? extends Object> but the sub-expression has type List<?>, which has mismatched nullability of type parameters
Example and expected behavior
c2 = b ? l : o reports, at l, the same message as c1 = l (JSpecify mode on):
incompatible nullability in type argument for E of Collection -> upper bound of wildcard: source has @Nullable Object where target requires Object
source: List<?>
^
target: Collection<? extends Object>
^^^^^^
note: the unbounded wildcard ? in List<?> has the upper bound of type parameter E of List, which is @Nullable Object (JLS 5.1.10)
Proposed solution
Route GenericsChecks.reportMismatchedTypeForTernaryOperator through reportNullabilityMismatch, as the assignment, argument, and return reporters are, and decide the same for the method-reference and override reporters, which ask the same check.
Activity