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
Enforce receiver-substituted bounds in generic method-reference inference #2181
Generic method-reference inference may accept an inferred nullable type argument that violates a bound after substituting the receiver's type arguments. The review reported this case; it has not been independently reproduced for this issue.
For example, in JSpecify mode:
importjava.util.function.Supplier;
importorg.jspecify.annotations.NullMarked;
importorg.jspecify.annotations.Nullable;
@NullMarkedabstractclassExample {
staticclassBox<Textends@NullableObject> {}
abstractstaticclassFactory<Xextends@NullableObject> {
abstract <TextendsX> Box<T> box();
}
staticvoidaccept(Supplier<Box<@NullableString>> supplier) {}
staticvoidcheck(Factory<String> nonNull, Factory<@NullableString> nullable) {
accept(nonNull::box); // The receiver's bound for T is non-null.accept(nullable::box); // The receiver's bound for T allows null.
}
}
The reported concern is that inference registers the declared method type parameter without applying the receiver substitution to its bound. It may then infer T as nullable for the first reference, despite the non-null receiver-substituted bound.
Required change
In nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java and the associated constraint-solving code, enforce the method type parameter's receiver-substituted upper bound during omitted-type-argument inference for method references. Preserve the behavior for bounds that allow nullable type arguments.
Acceptance criteria
Add a regression test for an inline generic method reference whose receiver makes the method type parameter's upper bound non-null. When the target requires a nullable type argument, report an inference failure with WarnOnGenericInferenceFailure enabled.
Add a control using a nullable receiver type argument. Accept the reference when the target and substituted bound permit nullable inference.
Check that inference and compatibility behavior remains appropriate when inference warnings are disabled.
Activity
msridhar commentedon Nov 29, 2026
TODO: check if the solver rewrite fixes this one