Skip to content

Commit

Permalink
Don't report @nullable type argument errors for unmarked classes (#958)
Browse files Browse the repository at this point in the history
Co-authored-by: Manu Sridharan <msridhar@gmail.com>
  • Loading branch information
haewiful and msridhar authored Jun 15, 2024
1 parent 9860ab2 commit 2f62d78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,13 @@ public Description matchParameterizedType(ParameterizedTypeTree tree, VisitorSta
return Description.NO_MATCH;
}
if (config.isJSpecifyMode()) {
GenericsChecks.checkInstantiationForParameterizedTypedTree(
tree, state, this, config, handler);
Symbol baseClass = ASTHelpers.getSymbol(tree);
boolean isNullUnmarked =
baseClass != null && codeAnnotationInfo.isSymbolUnannotated(baseClass, config, handler);
if (!isNullUnmarked) {
GenericsChecks.checkInstantiationForParameterizedTypedTree(
tree, state, this, config, handler);
}
}
return Description.NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,34 @@ public void testRawTypeReceiverCast() {
.doTest();
}

@Test
public void testUseOfUnannotatedCode() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.NullMarked;",
"import org.jspecify.annotations.NullUnmarked;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" @NullUnmarked",
" static class NullUnmarkedClass<T> {",
" }",
" @NullMarked",
" static class MarkedClass {",
" static void testInstantiation() {",
" // NullUnmarkedClass is marked @NullUnmarked, so we get no error",
" // even though the type variable does not have a @Nullable upper bound",
" new NullUnmarkedClass<@Nullable String>();",
" }",
" static void testAssignment() {",
" NullUnmarkedClass<@Nullable Integer> var = null;",
" }",
" }",
"}")
.doTest();
}

public void boxInteger() {
makeHelper()
.addSourceLines(
Expand Down

0 comments on commit 2f62d78

Please sign in to comment.