From 5f545de16f44aa23befd6f1407919766a28116da Mon Sep 17 00:00:00 2001 From: Abhijit Kulkarni Date: Sat, 21 Oct 2023 15:04:02 -0700 Subject: [PATCH] Adding a test case for lambdas without JSpecify mode --- .../NullAwayJSpecifyGenericsTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java index 7d445cedd4..0d6bcd0093 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java @@ -606,6 +606,28 @@ public void testForLambdasInAnAssignment() { .doTest(); } + @Test + public void testForLambdasInAnAssignmentWithoutJSpecifyMode() { + makeHelperWithoutJSpecifyMode() + .addSourceLines( + "Test.java", + "package com.uber;", + "import org.jspecify.annotations.Nullable;", + "class Test {", + " interface A {", + " String function(T1 o);", + " }", + " static void testPositive() {", + " // Using outside JSpecify Mode So we don't get a bug here", + " A<@Nullable Object> p = o -> o.toString();", + " }", + " static void testNegative() {", + " A p = o -> o.toString();", + " }", + "}") + .doTest(); + } + @Test public void testForDiamondInAnAssignment() { makeHelper() @@ -1426,4 +1448,8 @@ private CompilationTestHelper makeHelper() { Arrays.asList( "-XepOpt:NullAway:AnnotatedPackages=com.uber", "-XepOpt:NullAway:JSpecifyMode=true")); } + + private CompilationTestHelper makeHelperWithoutJSpecifyMode() { + return makeTestHelperWithArgs(Arrays.asList("-XepOpt:NullAway:AnnotatedPackages=com.uber")); + } }