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 dereferenced expression is @Nullable in Stream pipeline after Class::cast #1808
When running NullAway with the experimental JSpecify engine enabled (-XepOpt:NullAway:JSpecifyExperimental=true), NullAway reports a false positive [NullAway] dereferenced expression 's' is @Nullable inside a stream pipeline.
Even though Class::cast guarantees a non-null return value of that specific type, the experimental generics engine fails to propagate this non-null type argument into the subsequent stream operations, causing the next lambda parameter s to be treated as nullable.
Note: This error does not occur when JSpecifyExperimental is disabled.
Steps to Reproduce
Compile the following code snippet with NullAway and -XepOpt:NullAway:JSpecifyExperimental=true enabled:
importjava.io.Serializable;
importjava.util.List;
publicclassTester {
publicstaticvoidmain(String[] args) {
List<Serializable> list = List.of("Hello", 100);
List<String> stringsLongerThanThree = list.stream()
.filter(String.class::isInstance)
.map(String.class::cast) // Yields Stream<String>, should be non-null generic argument
.filter(s -> s.length() > 3) // <-- Fails here only with JSpecifyExperimental active
.toList();
System.out.println(stringsLongerThanThree);
}
}
Expected Behavior
The experimental JSpecify mode should properly propagate the type argument from .map(String.class::cast) as a non-null String type, meaning s in .filter(s -> ...) should be recognized as safely non-null.
Activity
msridhar commentedon Sep 3, 2026
Yup, agreed on this one, in fact I've seen it before on other programs. Will work on getting a fix in soon-ish.
msridhar commentedon Oct 3, 2026
See also PicnicSupermarket/error-prone-support#2299 (comment)
Apply conditional library return models to method references
Apply conditional library return models to method references (#1968)