Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0472a25
Report a generic nullability mismatch as a marked diff of the two types
vlsi Sep 9, 2026
880e3b2
Group the mismatch message tests by the part of the message they check
vlsi Oct 12, 2026
83b7d1c
Offer the required type where one type instance fills two type arguments
vlsi Oct 12, 2026
01b758b
Stop the mismatch traversal at a bound comparison already in progress
vlsi Nov 27, 2026
561c91d
Adapt the mismatch message to master without #1834
vlsi Nov 27, 2026
c9761f0
Record the mismatch positions while the nullability check runs
vlsi Nov 27, 2026
df65821
Keep the declaration fix valid for qualified names, varargs, and shar…
vlsi Nov 27, 2026
e022a7a
Print the view the rejected comparison used on the found as line
vlsi Nov 27, 2026
87a64bb
Rejoin comments the formatter broke after one word
vlsi Nov 27, 2026
ecb7afc
Label the two sides of a nullability mismatch source and target
vlsi Nov 27, 2026
697497e
Attach the declaration edit only to a local variable
vlsi Nov 28, 2026
1c34a37
Follow a supertype view through the declared supertype
vlsi Nov 28, 2026
43d0bd6
Name the type parameter of a wildcard marked on the viewed source
vlsi Nov 28, 2026
ef9de37
Test the suppressed-mismatch shortcut through an excluded class
vlsi Nov 28, 2026
c07bd0c
Test that a parameter or field source is never looked up
vlsi Nov 28, 2026
72b7001
Keep following the written source through a nested supertype view
vlsi Nov 28, 2026
014cd5d
Withhold the declaration edit where brackets follow the name
vlsi Nov 28, 2026
62ec1d0
Say that the declaration edit needs the type before the name
vlsi Nov 28, 2026
31cda79
Say which tracks a view re-views and which variables get the edit
vlsi Nov 28, 2026
d113efb
Test that a pattern or resource variable gets no declaration edit
vlsi Nov 28, 2026
0e2f51b
Name the positions of a generic nullability mismatch in JLS terms
vlsi Nov 28, 2026
dff79d5
Give the same wording to both wildcard notes and update the other mod…
vlsi Nov 28, 2026
2c39198
Keep the approved wording of the note for an unbounded wildcard
vlsi Nov 28, 2026
06c4764
Describe the note and its elision rule as the code builds them
vlsi Nov 28, 2026
da8978d
Link the tests that pin a known message gap to their issues
vlsi Nov 29, 2026
778449f
Print a fix type only as Java that compiles and keeps its annotations
vlsi Nov 29, 2026
12d2b7d
Check that applying a possible fix round-trips through NullAway
vlsi Nov 29, 2026
f5c6bfe
Offer the source fix of a local only where every value of the local a…
vlsi Nov 29, 2026
869299e
Check every bound note a message test compares
vlsi Nov 29, 2026
a51be98
Keep the bound note consistent with the bound the check compared
vlsi Nov 29, 2026
f3c5714
Merge branch 'refs/heads/claude/r3-w1c-notes-49da8e' into claude/addr…
vlsi Nov 29, 2026
19e2792
Merge W1-A into the C2 printing fixes
vlsi Nov 29, 2026
7d55aca
Merge W1-C into the C2 printing fixes
vlsi Nov 29, 2026
553fd9b
Name what a type argument must match and what each count counts
vlsi Nov 30, 2026
85e55b2
Offer the source fix of a local only where each of its values is show…
vlsi Nov 30, 2026
bf28d51
Withhold a fix the printer cannot write as declared, and check each l…
vlsi Nov 30, 2026
1759a84
Print a captured bound by type parameter and withhold a lambda parame…
vlsi Nov 30, 2026
d252b10
Remove the possible fix line from generic mismatch messages
vlsi Nov 30, 2026
25871d2
Give each nested marked node its own caret row and share path prefixes
vlsi Nov 30, 2026
9e5c423
Put a caret number that would collide on its own row
vlsi Nov 30, 2026
af204ca
Restore a test source and test number rows above a deeper caret row
vlsi Nov 30, 2026
ed7b2fa
Descend one type-path step in one place, and close round-4 test gaps
vlsi Nov 30, 2026
1ddcbcf
Test the class check of a source caret, and correct comments
vlsi Nov 30, 2026
d75bba5
Name the issue for the missing note below an enclosing type
vlsi Nov 30, 2026
c863efe
Keep the source caret on the written type and derive the note from on…
vlsi Dec 1, 2026
ce35094
Name a bound's type parameter only where it declares the compared bound
vlsi Dec 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ class Test {
void testCall() {
ParameterAnnotation.takesNullableArray(nonNullArray);
ParameterAnnotation.takesNullableArray(nullableArray);
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
ParameterAnnotation.takesNullableArray(nullableElements);
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
ParameterAnnotation.takesNullableArray(nullableArrayAndElements);
ParameterAnnotation.takesNullableElements(nonNullArray);
ParameterAnnotation.takesNullableElements(nullableElements);
Expand Down Expand Up @@ -339,12 +339,12 @@ void test() {
}

int nullableElementsLength = ReturnAnnotation.returnNullableElements().length;
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
String[] nullableElements = ReturnAnnotation.returnNullableElements();

// BUG: Diagnostic contains: dereferenced expression 'ReturnAnnotation.returnNullableArrayAndElements()' is @Nullable
int nullableArrayAndElementsLength = ReturnAnnotation.returnNullableArrayAndElements().length;
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
String @Nullable [] nullableArrayAndElements =
ReturnAnnotation.returnNullableArrayAndElements();
}
Expand Down Expand Up @@ -381,7 +381,7 @@ void test() {

int nullableComponentArraysLength =
ReturnAnnotation.returnNullableComponentArrays2D().length;
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has String @Nullable [] where target requires String []
String[][] nullableComponentArrays =
ReturnAnnotation.returnNullableComponentArrays2D();
// TODO: This should report a nullable dereference. NullAway currently loses the
Expand All @@ -391,7 +391,7 @@ void test() {

// BUG: Diagnostic contains: dereferenced expression 'ReturnAnnotation.returnNullableOuterAndComponentArrays2D()' is @Nullable
int nullableOuterAndComponentArraysLength = ReturnAnnotation.returnNullableOuterAndComponentArrays2D().length;
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has String @Nullable [] where target requires String []
String @Nullable [][] nullableOuterAndComponentArrays =
ReturnAnnotation.returnNullableOuterAndComponentArrays2D();
}
Expand Down Expand Up @@ -656,21 +656,21 @@ public void loadLibraryModuleMethodReturnTypeNestedAnnotation() {
class Test {
void testCall() {
// -- Type argument nullability
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in type argument for E of List: source has @Nullable String where target requires String
List<String> typeArg1 = ReturnAnnotation.nestedAnnotTypeArg();
List<@Nullable String> typeArg2 = ReturnAnnotation.nestedAnnotTypeArg();
// -- Array Element nullability
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
String[] arrayElement1 = ReturnAnnotation.nestedAnnotArrayElement();
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable String where target requires String
String @Nullable [] arrayElement2 = ReturnAnnotation.nestedAnnotArrayElement();
@Nullable String [] arrayElement3 = ReturnAnnotation.nestedAnnotArrayElement();
// -- mixed type nullability
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable List<@Nullable Integer> where target requires List<Integer>
List<Integer>[] mixed1 = ReturnAnnotation.nestedAnnotMixed();
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type -> type argument for E of List: source has @Nullable Integer where target requires Integer
@Nullable List<Integer>[] mixed2 = ReturnAnnotation.nestedAnnotMixed();
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type: source has @Nullable List<@Nullable Integer> where target requires List<@Nullable Integer>
List<@Nullable Integer>[] mixed3 = ReturnAnnotation.nestedAnnotMixed();
@Nullable List<@Nullable Integer>[] mixed4 = ReturnAnnotation.nestedAnnotMixed();
}
Expand Down Expand Up @@ -718,11 +718,11 @@ void testCall() {
@Nullable List<Integer>[] nonNullTypeArgMixed = (@Nullable List<Integer>[]) new List<?>[3];
// === test calls
ParameterAnnotation.nestedAnnotations(nullableTypeArg, nullableArray, nullableMixed);
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in type argument for E of List: a non-wildcard type argument must have the same nullability in source and target; source has String where target requires @Nullable String
ParameterAnnotation.nestedAnnotations(nonNullTypeArg, nullableArray, nullableMixed);
ParameterAnnotation.nestedAnnotations(nullableTypeArg, nonNullArray, nullableMixed);
ParameterAnnotation.nestedAnnotations(nullableTypeArg, nullableArray, nonNullArrayMixed);
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: incompatible nullability in component type -> type argument for E of List: a non-wildcard type argument must have the same nullability in source and target; source has Integer where target requires @Nullable Integer
ParameterAnnotation.nestedAnnotations(nullableTypeArg, nullableArray, nonNullTypeArgMixed);
}
}
Expand Down
32 changes: 20 additions & 12 deletions nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,9 @@ private Description createErrorDescriptionImpl(
@Nullable Symbol nonNullTarget,
@Nullable ExpressionTree nullableExpression) {
Description.Builder builder = descriptionBuilder.setMessage(errorMessage.message);
String checkName = CORE_CHECK_NAME;
if (errorMessage.messageType.equals(GET_ON_EMPTY_OPTIONAL)) {
checkName = OPTIONAL_CHECK_NAME;
} else if (errorMessage.messageType.equals(FIELD_NO_INIT)
|| errorMessage.messageType.equals(METHOD_NO_INIT)
|| errorMessage.messageType.equals(NONNULL_FIELD_READ_BEFORE_INIT)) {
checkName = INITIALIZATION_CHECK_NAME;
}

// Mildly expensive state.getPath() traversal, occurs only once per potentially
// reported error.
if (hasPathSuppression(state.getPath(), checkName)) {
// Mildly expensive state.getPath() traversal. A reporter whose message costs more to build,
// as for a generic nullability mismatch, runs it once more before building the message.
if (isSuppressed(errorMessage.messageType, state)) {
return Description.NO_MATCH;
}

Expand Down Expand Up @@ -315,6 +306,23 @@ private Description createErrorDescriptionImpl(
((JCTree) nullableExpression).pos().getStartPosition());
}

/**
* Returns whether an error of {@code messageType} at {@code state.getPath()} is suppressed, so
* that {@link #createErrorDescription} would drop it. A reporter whose message is costly to build
* asks first.
*/
public boolean isSuppressed(ErrorMessage.MessageTypes messageType, VisitorState state) {
String checkName = CORE_CHECK_NAME;
if (messageType.equals(GET_ON_EMPTY_OPTIONAL)) {
checkName = OPTIONAL_CHECK_NAME;
} else if (messageType.equals(FIELD_NO_INIT)
|| messageType.equals(METHOD_NO_INIT)
|| messageType.equals(NONNULL_FIELD_READ_BEFORE_INIT)) {
checkName = INITIALIZATION_CHECK_NAME;
}
return hasPathSuppression(state.getPath(), checkName);
}

private static boolean canHaveSuppressWarningsAnnotation(Tree tree) {
return tree instanceof MethodTree
|| (tree instanceof ClassTree classTree && classTree.getSimpleName().length() != 0)
Expand Down
Loading
Loading