-
Notifications
You must be signed in to change notification settings - Fork 327
Open
1 / 11 of 1 issue completedOpen
1 / 11 of 1 issue completed
Copy link
Labels
bugjspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)
Description
Explicit use of .iterator()/.next() is checked correctly (if Iterator is null-marked by LibraryModels), but the equivalent for-each loop is not:
void use(Integer x) {}
void f1(Iterable<@Nullable Integer> list) {
for (var it = list.iterator(); it.hasNext(); ) { use(it.next()); } // warning, it.next() is nullable
for (var it = list.iterator(); it.hasNext(); ) { int x = it.next(); } // warning, it.next() is nullable
for (Integer x : list) use(x); // no warning
for (int x : list) {} // no warning
}Also, I tested the analogous loops with an array, and found that there's no unboxing checking on either:
void f2(@Nullable Integer[] array) {
for (int i = 0; i < array.length; i++) { use(array[i]); } // warning, array[i] is nullable
for (int i = 0; i < array.length; i++) { int x = array[i]; } // no warning
for (Integer x : array) use(x); // warning, x is nullable
for (int x : array) {} // no warning
}Sub-issues
Metadata
Metadata
Assignees
Labels
bugjspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)