diff --git a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java index af79f42486..ef56490473 100644 --- a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java @@ -784,7 +784,7 @@ 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 = @@ -834,7 +834,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 = diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java index e7227064f3..58f09d1f8a 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java @@ -1494,6 +1494,34 @@ 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 {", + " public static A returnA(){", + " return new A();", + " }", + " public static A returnAWithParam(Object o){", + " return new A();", + " }", + " }", + " static void func(A a){", + " }", + " static void testNegative() {", + " func(A.returnA());", + " }", + " static void testNegative2() {", + " func(A.returnAWithParam(new Object()));", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(