Skip to content

Commit

Permalink
Merge branch 'master' into generics-package
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Nov 15, 2023
2 parents e6675b7 + 4af912d commit 5a4654b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nullaway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ tasks.register('buildWithNullAway', JavaCompile) {
sourceSets.main.compileClasspath)
options.errorprone.enabled = true
options.errorprone {
option("NullAway:AnnotatedPackages", "com.uber,org.checkerframework.nullaway")
option("NullAway:AnnotatedPackages", "com.uber,org.checkerframework.nullaway,com.google.common")
option("NullAway:CastToNonNullMethod", "com.uber.nullaway.NullabilityUtil.castToNonNull")
option("NullAway:CheckOptionalEmptiness")
option("NullAway:AcknowledgeRestrictiveAnnotations")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,17 @@ public static Nullness getGenericReturnNullnessAtInvocation(
MethodInvocationTree tree,
VisitorState state,
Config config) {
if (!(tree.getMethodSelect() instanceof MemberSelectTree)) {
if (!(tree.getMethodSelect() instanceof MemberSelectTree) || invokedMethodSymbol.isStatic()) {
return Nullness.NONNULL;
}
Type methodReceiverType =
castToNonNull(
getTreeType(((MemberSelectTree) tree.getMethodSelect()).getExpression(), state));
return getGenericMethodReturnTypeNullness(
invokedMethodSymbol, methodReceiverType, state, config);
getTreeType(((MemberSelectTree) tree.getMethodSelect()).getExpression(), state);
if (methodReceiverType == null) {
return Nullness.NONNULL;
} else {
return getGenericMethodReturnTypeNullness(
invokedMethodSymbol, methodReceiverType, state, config);
}
}

/**
Expand Down Expand Up @@ -677,7 +680,7 @@ public static Nullness getGenericParameterNullnessAtInvocation(
MethodInvocationTree tree,
VisitorState state,
Config config) {
if (!(tree.getMethodSelect() instanceof MemberSelectTree)) {
if (!(tree.getMethodSelect() instanceof MemberSelectTree) || invokedMethodSymbol.isStatic()) {
return Nullness.NONNULL;
}
Type enclosingType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,52 @@ public void interactionWithContracts() {
.doTest();
}

@Test
public void testForStaticMethodCallAsAParam() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static class A<T> {",
" public static <T> A<T> returnA(){",
" return new A<T>();",
" }",
" public static <T> A<T> returnAWithParam(Object o){",
" return new A<T>();",
" }",
" }",
" static void func(A<Object> a){",
" }",
" static void testNegative() {",
" func(A.returnA());",
" }",
" static void testNegative2() {",
" func(A.returnAWithParam(new Object()));",
" }",
"}")
.doTest();
}

@Test
public void testForDiamondOperatorReturnedAsAMethodCaller() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static class B<T>{",
" String build(){return \"x\";}",
" }",
" static String testNegative() {",
" return new B<>().build();",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down

0 comments on commit 5a4654b

Please sign in to comment.