-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
import java.util.*;
import org.jspecify.annotations.*;
@NullMarked
class Test {
public static <T extends @Nullable Object> T firstOrDefault(List<T> list, T defaultValue) {
return list.isEmpty() ? defaultValue : list.get(0);
}
// expected an error here
String field = firstOrDefault(Collections.singletonList(null), "hello");
void takesNonNullString(String s) {}
void test() {
// expected an error here
takesNonNullString(firstOrDefault(Collections.singletonList(null), "hello"));
}
}I would expect an error since at both call sites, making the type argument @Nullable doesn't work (since call result is assigned to a @NonNull location), but making it @NonNull doesn't work either (since we're putting null in the singleton List). Am I missing something?
Metadata
Metadata
Assignees
Labels
No labels