NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

No error with `List<@Nullable String>`

Open sdeleuze opened this issue 8 months ago • 3 comments

Sorry if I miss something obvious, but I am not sure why NullAway 0.12.4 with Java 23, JSpecify mode enabled, and @NullMarked at package level does not report any error for this simple use case:

List<@Nullable String> listOfNullable = new ArrayList<>();
listOfNullable.add("foo");
listOfNullable.add(null);
listOfNullable.add("bar");
for (String element : listOfNullable) {
	System.out.println(element.toLowerCase());
}

You can find a related repro on https://github.com/sdeleuze/jspecify-nullway-demo/tree/generics-with-list, where ./gradlew clean build does not report any error. I see the same behavior with Supplier<@Nullable T>. IDEA reports a warning as expected.

sdeleuze avatar Mar 10 '25 14:03 sdeleuze

@sdeleuze can you show the example that uses Supplier<@Nullable T>? That might be a different issue. This could all be due to missing JDK models (#950) but I'm not sure yet.

msridhar avatar Mar 10 '25 14:03 msridhar

See https://github.com/sdeleuze/jspecify-nullway-demo/tree/generics-with-supplier.

sdeleuze avatar Mar 10 '25 15:03 sdeleuze

After further investigation this is in fact #950. That one is high on our priority list and I'll try to prioritize it even more, but it will take some time to address properly. I'm going to leave this issue open just to ensure we come back and test these specific scenarios.

msridhar avatar Mar 10 '25 19:03 msridhar