From b37f5f98c15c314f84be369692b64acff216d453 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sun, 11 Aug 2024 16:10:07 -0700 Subject: [PATCH] Add test for #1011 (#1018) We can enable the test on appropriate JDK versions once https://github.com/openjdk/jdk/pull/20460 lands. #1011 --- .../jspecify/BytecodeGenericsTests.java | 20 +++++++++++++++++++ .../lib/generics/JavaUtilFunctionMethods.java | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 test-java-lib/src/main/java/com/uber/lib/generics/JavaUtilFunctionMethods.java diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/BytecodeGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/BytecodeGenericsTests.java index d5e2dbec7b..7390f9594a 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/BytecodeGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/BytecodeGenericsTests.java @@ -3,6 +3,7 @@ import com.google.errorprone.CompilationTestHelper; import com.uber.nullaway.NullAwayTestsBase; import java.util.Arrays; +import org.junit.Ignore; import org.junit.Test; public class BytecodeGenericsTests extends NullAwayTestsBase { @@ -222,6 +223,25 @@ public void overrideReturnTypes() { .doTest(); } + @Test + @Ignore("Failing due to https://bugs.openjdk.org/browse/JDK-8337795") + // TODO Re-enable this test once the JDK bug is fixed, on appropriate JDK versions + // See https://github.com/uber/NullAway/issues/1011 + public void callMethodTakingJavaUtilFunction() { + makeHelper() + .addSourceLines( + "Test.java", + "package com.uber;", + "import org.jspecify.annotations.Nullable;", + "import com.uber.lib.generics.JavaUtilFunctionMethods;", + "class Test {", + " static void testNegative() {", + " JavaUtilFunctionMethods.withFunction(s -> { return null; });", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList( diff --git a/test-java-lib/src/main/java/com/uber/lib/generics/JavaUtilFunctionMethods.java b/test-java-lib/src/main/java/com/uber/lib/generics/JavaUtilFunctionMethods.java new file mode 100644 index 0000000000..91a4d9f379 --- /dev/null +++ b/test-java-lib/src/main/java/com/uber/lib/generics/JavaUtilFunctionMethods.java @@ -0,0 +1,9 @@ +package com.uber.lib.generics; + +import java.util.function.Function; +import org.jspecify.annotations.Nullable; + +public class JavaUtilFunctionMethods { + + public static void withFunction(Function f) {} +}