Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2e3f4c6
Resolve an inference variable that a type variable admitting null rea…
vlsi Oct 10, 2026
7034a6f
Keep an inferred type variable only where its bound admits null
vlsi Nov 24, 2026
a75e2d0
Link the known gaps in the new tests to their issues
vlsi Nov 24, 2026
0c35015
Report a captured nullable-bound argument and name the declaring element
vlsi Nov 24, 2026
03c5cd0
Report a wildcard argument only where its type parameter admits null
vlsi Nov 24, 2026
b72d50f
Check only a bare type variable passed for a non-null `? extends U`
vlsi Nov 25, 2026
9a5b8b8
Decide parametric nullness of a capture by one predicate
vlsi Nov 25, 2026
4df1243
Run nullable-bound inference only with JSpecifyExperimental
vlsi Nov 26, 2026
3745f55
Describe the inferred-nullness steps precisely in Javadoc
vlsi Nov 26, 2026
8aa4d1a
Build Calcite at a commit that includes apache/calcite#5454
vlsi Nov 26, 2026
6a9df20
Accept a capture-typed value where the same capture is expected
vlsi Nov 26, 2026
fb2d558
Name which capture accepts a NO_CHANGE value; test the ? super T boun…
vlsi Nov 26, 2026
c01f729
Carry nullness across a declared bound between inference variables
vlsi Nov 26, 2026
494b790
Keep null-unmarked bounds out of the declared-bound edge
vlsi Nov 26, 2026
783aabc
Test the library-model and nested cases of declared-bound edges
vlsi Nov 26, 2026
89a4ec3
Name every ? super target that accepts a NO_CHANGE value; test the ga…
vlsi Nov 26, 2026
5887633
Link the nested-bound false negative to #2192
vlsi Nov 26, 2026
cebc28c
Drop the bound-nullability memo from the constraint solver
vlsi Nov 26, 2026
13f0f18
State the declared-bound edge rule once, with its chain closure
vlsi Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
- project: calcite
url: https://github.com/apache/calcite.git
branch: main
sha: 713faf069e246f3430ae23ead1f90430c672cc15
sha: dde58eb5a30f245f975d55f88ce2e861a1e82668
build: JAVA_HOME="$JAVA_HOME_21_X64" ./gradlew --init-script use-snapshot.gradle.kts -PenableErrorprone classes jmhClasses
permissions:
contents: read
Expand Down
32 changes: 32 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,38 @@ public interface Config {
/** Should PolyNull library models be enabled? */
boolean isPolyNullLibraryModelsEnabled();

/**
* Should generic inference account for the nullness of an unannotated type variable, a capture
* included, whose bound admits null, and read a declared bound {@code U extends R} between two
* type variables of a call as {@code U <: R}? True where both JSpecifyMode and
* JSpecifyExperimental are set. Where it is false, every inference variable that no constraint
* fixes is {@code @NonNull}, and the checks of a generic constructor at a diamond and of a
* generic method reference use the declared types.
*
* <p>Where it is true, an inference variable that no constraint fixes and that such a type
* variable flows into is {@link
* com.uber.nullaway.generics.ConstraintSolver.InferredNullability#TYPE_VARIABLE_OR_NULLABLE}
* where the bounds of both that type variable and the inference variable are explicitly nullable,
* and {@link
* com.uber.nullaway.generics.ConstraintSolver.InferredNullability#TYPE_VARIABLE_OR_NONNULL}
* otherwise. {@code GenericsUtils.typeVariableWithNullableBound} decides which bounds are
* explicitly nullable. With HandleWildcardGenerics also set, inference fails where an uncaptured
* type variable whose bound is explicitly nullable is passed for {@code ? extends U} and the
* bound of {@code U} excludes null. A generic constructor at a diamond and a generic method
* reference are checked against the types javac inferred for them.
*
* <p>Where it is true, inference also reads a declared bound {@code U extends R} between two type
* variables of one call, where the use of {@code R} carries no nullness annotation, as {@code U
* <: R}, and follows a chain of such bounds. {@code @Nullable} and the flow of an unannotated
* type variable whose bound admits null pass from {@code U} to {@code R}, and {@code @NonNull}
* passes from {@code R} to {@code U}. So {@code viaBoundOne(null).hashCode()} with {@code <R
* extends @Nullable Object, U extends R> R viaBoundOne(U u)} is reported, though no type variable
* whose bound admits null is passed. Inference reads no {@code U <: R} where the declaration of
* {@code U} makes its bound nullable: where a library model does so, or where {@code U} is
* declared in unannotated code.
*/
boolean isNullableBoundInferenceEnabled();

/**
* Should wildcard-aware generic nullability checks be enabled? These also compute {@link
* Nullness#NO_CHANGE} for the values listed there, such as the result of {@code Box<? extends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public boolean isPolyNullLibraryModelsEnabled() {
throw new IllegalStateException(ERROR_MESSAGE);
}

@Override
public boolean isNullableBoundInferenceEnabled() {
throw new IllegalStateException(ERROR_MESSAGE);
}

@Override
public boolean handleWildcardGenerics() {
throw new IllegalStateException(ERROR_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ final class ErrorProneCLIFlagsConfig implements Config {
private final boolean acknowledgeAndroidRecent;
private final boolean jspecifyMode;
private final boolean polyNullLibraryModelsEnabled;
private final boolean nullableBoundInferenceEnabled;
private final boolean handleWildcardGenerics;
private final boolean warnOnInferenceFailure;
private final ImmutableSet<MethodClassAndName> knownInitializers;
Expand Down Expand Up @@ -311,6 +312,7 @@ final class ErrorProneCLIFlagsConfig implements Config {
acknowledgeAndroidRecent = flags.getBoolean(FL_ACKNOWLEDGE_ANDROID_RECENT).orElse(false);
jspecifyMode = flags.getBoolean(FL_JSPECIFY_MODE).orElse(false);
polyNullLibraryModelsEnabled = jspecifyMode && jspecifyExperimental;
nullableBoundInferenceEnabled = jspecifyMode && jspecifyExperimental;
handleWildcardGenerics =
flags.getBoolean(FL_HANDLE_WILDCARD_GENERICS).orElse(jspecifyExperimental);
assertsEnabled = flags.getBoolean(FL_ASSERTS_ENABLED).orElse(false);
Expand Down Expand Up @@ -624,6 +626,11 @@ public boolean isPolyNullLibraryModelsEnabled() {
return polyNullLibraryModelsEnabled;
}

@Override
public boolean isNullableBoundInferenceEnabled() {
return nullableBoundInferenceEnabled;
}

@Override
public boolean handleWildcardGenerics() {
return handleWildcardGenerics;
Expand Down
6 changes: 4 additions & 2 deletions nullaway/src/main/java/com/uber/nullaway/Nullness.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public enum Nullness implements AbstractValue<Nullness> {
*
* <p>A dereference of the value is reported, since the value is not null-exclusive under every
* parameterization. An assignment, an argument, a return, or an array store accepts the value
* where nullness subtyping holds: where the target's type is {@code T}, or a capture of {@code ?
* super T}, without {@code @NonNull}, as {@link
* where nullness subtyping holds: where the target's type carries no {@code @NonNull} and is the
* value's own type (for example the capture of {@code ? extends T} that javac infers for a
* generic parameter), a type variable that the value's type reaches through non-nullable bounds
* (for example {@code T}), or a capture of {@code ? super} either of those types, as {@link
* com.uber.nullaway.generics.GenericsChecks#acceptsNoChangeValue} decides. At any other target
* the value is {@link #NULLABLE}, and so is a variable of another type that dataflow assigns it
* to. Generic method inference takes no nullness constraint from the value and infers {@code T}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import javax.lang.model.element.Element;
import org.jspecify.annotations.Nullable;

/**
* An interface for solving constraints on type variables, such as subtype relationships between
Expand Down Expand Up @@ -62,14 +63,51 @@ class UnsatisfiableConstraintsException extends RuntimeException {
/** Whether a {@code @Nullable} constraint conflicts with the type variable's upper bound. */
private final boolean causedByNonNullUpperBound;

/**
* The type variable with an explicitly nullable bound that was passed for {@code ? extends}
* {@link #typeVariable} and so constrains {@link #typeVariable} to be {@code @Nullable}; {@code
* null} where another constraint caused the conflict.
*/
private final @Nullable Type nullableBoundTypeVariable;

/**
* The type variable whose declared bound makes the bound of {@link #nullableBoundTypeVariable}
* explicitly nullable: that type variable itself, or one its bound reaches through other type
* variables; {@code null} exactly where {@link #nullableBoundTypeVariable} is.
*/
private final @Nullable Element typeVariableWithNullableBound;

public UnsatisfiableConstraintsException(Element typeVariable) {
this(typeVariable, false);
}

public UnsatisfiableConstraintsException(
Element typeVariable, boolean causedByNonNullUpperBound) {
this(typeVariable, causedByNonNullUpperBound, null, null);
}

/**
* Creates an exception for a {@code typeVariable} whose bound excludes null, where {@code
* nullableBoundTypeVariable}, a type variable with an explicitly nullable bound, was passed for
* {@code ? extends typeVariable}, and the declared bound of {@code
* typeVariableWithNullableBound} makes that bound explicitly nullable.
*/
public UnsatisfiableConstraintsException(
Element typeVariable,
Type nullableBoundTypeVariable,
Element typeVariableWithNullableBound) {
this(typeVariable, true, nullableBoundTypeVariable, typeVariableWithNullableBound);
}

private UnsatisfiableConstraintsException(
Element typeVariable,
boolean causedByNonNullUpperBound,
@Nullable Type nullableBoundTypeVariable,
@Nullable Element typeVariableWithNullableBound) {
this.typeVariable = typeVariable;
this.causedByNonNullUpperBound = causedByNonNullUpperBound;
this.nullableBoundTypeVariable = nullableBoundTypeVariable;
this.typeVariableWithNullableBound = typeVariableWithNullableBound;
}

public Element getTypeVariable() {
Expand All @@ -79,6 +117,14 @@ public Element getTypeVariable() {
public boolean isCausedByNonNullUpperBound() {
return causedByNonNullUpperBound;
}

public @Nullable Type getNullableBoundTypeVariable() {
return nullableBoundTypeVariable;
}

public @Nullable Element getTypeVariableWithNullableBound() {
return typeVariableWithNullableBound;
}
}

/**
Expand All @@ -97,14 +143,49 @@ public boolean isCausedByNonNullUpperBound() {
void addSubtypeConstraint(Type subtype, Type supertype, boolean localVariableType)
throws UnsatisfiableConstraintsException;

/** The nullness the solver found for an inference variable. */
enum InferredNullability {
/**
* A constraint fixed the variable to be non-null, or no constraint fixed it and no unannotated
* type variable that is not under inference and whose bound admits null flowed into it, so
* non-null is the least solution. The solver tracks such a flow only where {@link
* com.uber.nullaway.Config#isNullableBoundInferenceEnabled} holds; otherwise every variable
* that no constraint fixed is {@code NONNULL}.
*/
NONNULL,
NULLABLE
/** A constraint fixed the variable to be nullable. */
NULLABLE,
/**
* No constraint fixed the variable, a type variable {@code T} whose bound is explicitly
* nullable flowed into it, and the variable's own bound is explicitly nullable, as {@link
* GenericsUtils#typeVariableWithNullableBound} decides it. Where javac inferred a type with
* parametric nullness ({@link GenericsUtils#hasParametricNullness}), a capture included, the
* variable is that type with no synthetic annotation; where javac inferred an intersection
* type, it carries no annotation; where javac inferred any other type, such as the least upper
* bound of {@code T} and {@code String}, or a type variable {@code R} whose bound excludes null
* for {@code T extends @Nullable R}, the variable is {@code @Nullable}, the least type that
* holds a null {@code T}.
*/
TYPE_VARIABLE_OR_NULLABLE,
/**
* No constraint fixed the variable and an unannotated type variable that is not under inference
* and whose bound admits null flowed into it, but {@link #TYPE_VARIABLE_OR_NULLABLE} does not
* apply: no such type variable has an explicitly nullable bound, or the variable's own bound is
* not explicitly nullable. Where javac inferred a type with parametric nullness ({@link
* GenericsUtils#hasParametricNullness}), a capture included, the variable is that type with no
* synthetic annotation; where javac inferred an intersection type, it carries no annotation;
* where javac inferred any other type, the variable is {@code @NonNull}, as if no type variable
* had flowed into it.
*/
TYPE_VARIABLE_OR_NONNULL;
}

/**
* Solve the constraints, returning a map from inference variables to their inferred nullability.
* The map only contains inference variables that appear in constraints.
* The map only contains inference variables that appear in constraints or, where {@link
* com.uber.nullaway.Config#isNullableBoundInferenceEnabled} holds, that such a variable reaches
* through a chain of declared bounds read as {@code U <: R}: for {@code <Q, R extends Q, U
* extends R>} with only {@code U} constrained, the map holds {@code U}, {@code R}, and {@code Q}.
*
* @return a map from inference variables to their inferred nullability
* @throws UnsatisfiableConstraintsException if the constraints are determined to be unsatisfiable
Expand Down
Loading
Loading