Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
bfed991
WIP
msridhar Jul 8, 2025
0f0d3ab
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 1, 2025
6a889ce
test case
msridhar Aug 1, 2025
5982410
WIP
msridhar Aug 2, 2025
9d7ac36
WIP
msridhar Aug 2, 2025
320d900
more
msridhar Aug 2, 2025
3d4ee01
WIP
msridhar Aug 2, 2025
3dfbd32
WIP
msridhar Aug 2, 2025
5e3ae6f
WIP
msridhar Aug 2, 2025
a2b1c38
WIP
msridhar Aug 2, 2025
6379b3b
WIP
msridhar Aug 2, 2025
3450cda
WIP
msridhar Aug 2, 2025
3a81eea
WIP
msridhar Aug 2, 2025
1009394
WIP
msridhar Aug 2, 2025
3a1d716
something works
msridhar Aug 3, 2025
4d3d9c3
delete unused parameter
msridhar Aug 3, 2025
42ba7bd
cleanup
msridhar Aug 3, 2025
143a1c8
tweak
msridhar Aug 3, 2025
bd77f67
WIP
msridhar Aug 3, 2025
cb4da30
tweaks
msridhar Aug 4, 2025
e456d54
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 4, 2025
787d74d
WIP
msridhar Aug 6, 2025
97503b2
WIP
msridhar Aug 6, 2025
8737d42
WIP
msridhar Aug 6, 2025
4a866f3
more
msridhar Aug 6, 2025
6c8042c
tweak
msridhar Aug 6, 2025
fa95c5c
more
msridhar Aug 6, 2025
323bf1e
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 7, 2025
d9b9f75
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 8, 2025
dcf9137
fix
msridhar Aug 12, 2025
a889427
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 12, 2025
5d16362
more fixes!
msridhar Aug 12, 2025
6749ecc
fix another test
msridhar Aug 13, 2025
480c339
WIP
msridhar Aug 13, 2025
90b6943
tests passing!
msridhar Aug 13, 2025
8434042
small optimization
msridhar Aug 13, 2025
0fd9239
more tests
msridhar Aug 13, 2025
1f119a1
avoid indirection through superclass
msridhar Aug 13, 2025
bd0ec0f
fix a couple things
msridhar Aug 13, 2025
a3ac99d
remove print
msridhar Aug 13, 2025
9922483
failing test
msridhar Aug 13, 2025
fe944c6
fix varargs bug
msridhar Aug 13, 2025
dcf95fc
another test
msridhar Aug 13, 2025
d1bbf28
tweak test
msridhar Aug 13, 2025
2862630
fix another bug
msridhar Aug 13, 2025
7db7443
cleanup
msridhar Aug 15, 2025
eb0c315
more cleanup
msridhar Aug 15, 2025
c023481
improve javadoc and rename exception type
msridhar Aug 15, 2025
3902921
remove dead code
msridhar Aug 15, 2025
304776f
improve test coverage
msridhar Aug 15, 2025
914bbba
javadoc on field
msridhar Aug 15, 2025
b34ef65
cleanup
msridhar Aug 15, 2025
0b6103b
tweaks
msridhar Aug 15, 2025
67c47a3
more
msridhar Aug 15, 2025
6264812
add todo
msridhar Aug 15, 2025
f1bd090
more
msridhar Aug 15, 2025
cf49448
more
msridhar Aug 15, 2025
45aad64
restore @Nullable annotation
msridhar Aug 15, 2025
fb97eb2
more tests
msridhar Aug 15, 2025
0f6a460
ignore test
msridhar Aug 15, 2025
825285b
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 16, 2025
1059f40
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 17, 2025
34dc49a
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 18, 2025
1d30dc9
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 19, 2025
04f7bff
fix covariant array subtyping
msridhar Aug 20, 2025
c9d7e08
remove useless statement
msridhar Aug 20, 2025
893b22e
comment on why unchecked exception
msridhar Aug 20, 2025
7ffb9da
delete bogus code and add comment
msridhar Aug 20, 2025
44b0e75
update javadoc
msridhar Aug 20, 2025
676b89c
improved comments
msridhar Aug 20, 2025
8ad8e7b
clarify capture variables
msridhar Aug 20, 2025
ad36de8
WIP
msridhar Aug 23, 2025
5147295
WIP
msridhar Aug 23, 2025
417b1b1
WIP
msridhar Aug 24, 2025
d8069af
more
msridhar Aug 24, 2025
c0210d8
Merge branch 'more-instance-state-in-generics-checks' into generics-t…
msridhar Aug 24, 2025
128a74f
cleanup
msridhar Aug 24, 2025
7520d48
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 24, 2025
4d710ae
Merge branch 'master' into generics-type-constraint-solver
msridhar Aug 24, 2025
ee2fdd6
More generics inference fixes (#1255)
msridhar Aug 24, 2025
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
8 changes: 8 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,12 @@ public interface Config {
* @return true if both type use and declaration annotation locations should be honored
*/
boolean isLegacyAnnotationLocation();

/**
* Checks if a warning should be issued when generic type inference fails to infer a type
* argument's nullability.
*
* @return true if a warning should be issued when generic type inference fails
*/
boolean warnOnGenericInferenceFailure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,9 @@ public boolean isJSpecifyMode() {
public boolean isLegacyAnnotationLocation() {
throw new IllegalStateException(ERROR_MESSAGE);
}

@Override
public boolean warnOnGenericInferenceFailure() {
throw new IllegalStateException(ERROR_MESSAGE);
}
}
1 change: 1 addition & 0 deletions nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum MessageTypes {
WRONG_OVERRIDE_RETURN_GENERIC,
WRONG_OVERRIDE_PARAM_GENERIC,
ASSIGN_NULLABLE_TO_NONNULL_ARRAY,
GENERIC_INFERENCE_FAILURE,
NULLABLE_ON_WRONG_NESTED_CLASS_LEVEL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ final class ErrorProneCLIFlagsConfig implements Config {
static final String FL_LEGACY_ANNOTATION_LOCATION =
EP_FL_NAMESPACE + ":LegacyAnnotationLocations";

static final String FL_WARN_ON_GENERIC_INFERENCE_FAILURE =
EP_FL_NAMESPACE + ":WarnOnGenericInferenceFailure";

static final String ANNOTATED_PACKAGES_ONLY_NULLMARKED_ERROR_MSG =
"DO NOT report an issue to Error Prone for this crash! NullAway configuration is "
+ "incorrect. "
Expand Down Expand Up @@ -221,6 +224,7 @@ final class ErrorProneCLIFlagsConfig implements Config {
private final boolean acknowledgeAndroidRecent;
private final boolean jspecifyMode;
private final boolean legacyAnnotationLocation;
private final boolean warnOnInferenceFailure;
private final ImmutableSet<MethodClassAndName> knownInitializers;
private final ImmutableSet<String> excludedClassAnnotations;
private final ImmutableSet<String> generatedCodeAnnotations;
Expand Down Expand Up @@ -305,6 +309,7 @@ final class ErrorProneCLIFlagsConfig implements Config {
+ FL_JSPECIFY_MODE
+ " is set ");
}
warnOnInferenceFailure = flags.getBoolean(FL_WARN_ON_GENERIC_INFERENCE_FAILURE).orElse(false);
autofixSuppressionComment = flags.get(FL_SUPPRESS_COMMENT).orElse("");
optionalClassPaths =
new ImmutableSet.Builder<String>()
Expand Down Expand Up @@ -597,6 +602,11 @@ public boolean isLegacyAnnotationLocation() {
return legacyAnnotationLocation;
}

@Override
public boolean warnOnGenericInferenceFailure() {
return warnOnInferenceFailure;
}

@AutoValue
abstract static class MethodClassAndName {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.uber.nullaway.generics;

import com.sun.tools.javac.code.Type;
import java.util.Map;
import javax.lang.model.element.Element;

/**
* An interface for solving constraints on type variables, such as subtype relationships between
* types. This is used to determine the nullability of inferred type arguments at generic method
* calls, constructor calls using the diamond operator, etc.
*/
public interface ConstraintSolver {

/**
* Exception thrown when the constraints added to the solver are determined to be unsatisfiable.
Comment thread
msridhar marked this conversation as resolved.
Resolved
*
* <p>This is an unchecked exception since in our current solver implementation it needs to be
* thrown from an implementation of javac's TypeVisitor interface, which does not allow checked
* exceptions.
*/
class UnsatisfiableConstraintsException extends RuntimeException {
public UnsatisfiableConstraintsException(String message) {
super(message);
}
}

/**
* Add a subtype constraint between two types. Also constrains nested types appropriately (e.g.,
* generic type parameters of the two types must have identical nullability).
*
* @param subtype the subtype
* @param supertype the supertype
* @param localVariableType whether this constraint arises from assigning to a local variable. In
* such a case, the top-level types are not constrained to be subtypes (as local variable
* types are separately inferred), but the nested types are still constrained.
* @throws UnsatisfiableConstraintsException if the constraints are determined to be unsatisfiable
*/
void addSubtypeConstraint(Type subtype, Type supertype, boolean localVariableType)
throws UnsatisfiableConstraintsException;

enum InferredNullability {
NONNULL,
NULLABLE
}

/**
* Solve the constraints, returning a map from type variables to their inferred nullability.
*
* @return a map from type variables to their inferred nullability
* @throws UnsatisfiableConstraintsException if the constraints are determined to be unsatisfiable
*/
Map<Element, InferredNullability> solve() throws UnsatisfiableConstraintsException;
}
Loading