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
JSpecifyExperimental: false positive for addAll with ? element type #1822
@NullMarkedclassTest {
publicCollection<Object> foo(List<?> list) {
List<Object> result = newArrayList<>();
// BUG: List<?> cannot be converted to Collection<? extends Object> (List<?> is a subtype of Collection<?>)result.addAll(list);
returnresult;
}
}
Shows compilation error:
[ERROR]Test.java[6,22]: [NullAway] incompatible types: List<?> cannot be converted to Collection<? extends Object> (List<?> is a subtype of Collection<?>)
The error message is bad on this one, but I think it's a real issue, since List<?> could contain null values. That's because its type variable has a nullable upper bound. Does that make sense? Sorry can provide links later if needed, I'm on my phone
See https://jspecify.dev/docs/user-guide/#wildcard-bounds. For unbounded wildcards in @NullMarked code, the default upper bound is the same as the upper bound of the corresponding type variable, which in this case is @Nullable Object, taking into account the JSpecify JDK model of List.
Activity
msridhar commentedon Sep 7, 2026
The error message is bad on this one, but I think it's a real issue, since
List<?>could contain null values. That's because its type variable has a nullable upper bound. Does that make sense? Sorry can provide links later if needed, I'm on my phoneunv-unv commentedon Sep 7, 2026
But I have
@NullMarkedannotation. SoList<?>should be non-nullable.msridhar commentedon Sep 7, 2026
See https://jspecify.dev/docs/user-guide/#wildcard-bounds. For unbounded wildcards in
@NullMarkedcode, the default upper bound is the same as the upper bound of the corresponding type variable, which in this case is@Nullable Object, taking into account the JSpecify JDK model ofList.unv-unv commentedon Sep 7, 2026
Is it possible to specify non-null question mark?
msridhar commentedon Sep 7, 2026
Yes! Write
List<? extends Object>. Object here is implicitly non-nullMark the type argument at fault in incompatible types diagnostics and…
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Say what the bound is where naming where it came from needs a second …
Say what the bound is where naming where it came from needs a second …
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types
Report a generic nullability mismatch as a marked diff of the two types