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
Enhance generic method inference to compute mappings from type variables to full types? #1585
Right now, our generic method inference computes only the top-level nullability for each type variable of a generic method. Our assumption was that we could rely on javac to correctly compute the type arguments otherwise. But, as #1473 and #1574 show, sometimes this is not the case, and it makes sense: computing the nullability-enhanced type of an actual parameter (particularly for its type arguments) requires extra logic that javac doesn't include. While our hacks seem to hold up for now, eventually, we probably want to enhance generic method inference to compute full mappings from type variables to (nullability-enhanced) types to fix this properly, relying on javac types where appropriate but not always. This could be fixed alongside #1291 which will also require a re-working of inference.
Box<Box<@Nullable String>> cannot be converted to Box<Box<String>>
var flat = nested.flatMap(box -> box);
^
Box<Box<String>> cannot be converted to Box<Box<@Nullable String>>
acceptsNested(flat);
^
The correct substitution is R = Box<@Nullable String>, giving flat type Box<Box<@Nullable String>>. Here R itself is non-null; the nullable annotation is inside its substituted type. Recording only the top-level nullability of R does not preserve that information. This is another case where inference needs to compute and propagate a full nullability-enhanced type substitution.
Activity
msridhar commentedon Oct 6, 2026
Another self-contained example motivating a proper reimplementation of generic method inference:
NullAway reports:
The correct substitution is
R = Box<@Nullable String>, givingflattypeBox<Box<@Nullable String>>. HereRitself is non-null; the nullable annotation is inside its substituted type. Recording only the top-level nullability ofRdoes not preserve that information. This is another case where inference needs to compute and propagate a full nullability-enhanced type substitution.msridhar commentedon Oct 9, 2026
Fixing this should address #1942
Compare an uninferred type variable of a generic constructor or metho…
Report a type variable whose bound admits null where a non-null wildc…
Allow nullable result types in Try.andThen() and andThenTry()
use nullRef() for null futures rejected by NullAway's generic inferen…
Pin the inference error for a qualified inner creation argument
Apply the qualifier's type arguments to qualified inner class creation (
Report a type variable whose bound admits null where a non-null wildc…
Report a type variable whose bound admits null where a non-null wildc…
Report a type variable whose bound admits null where a non-null wildc…
Report a type variable whose bound admits null where a non-null wildc…