diff --git a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle index 37021611d0..3ba4ff0a72 100644 --- a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle +++ b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle @@ -65,7 +65,7 @@ test { } // Tasks for testing on other JDK versions; see https://jakewharton.com/build-on-latest-java-test-through-lowest-java/ -[21, 22].each { majorVersion -> +[21, 23].each { majorVersion -> def jdkTest = tasks.register("testJdk$majorVersion", Test) { onlyIf { // Only run when using the latest Error Prone version diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index b511bf7d47..9d2de3dea1 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -48,7 +48,7 @@ def versions = [ // The version of Error Prone that NullAway is compiled and tested against errorProneApi : errorProneVersionToCompileAgainst, support : "27.1.1", - wala : "1.6.6", + wala : "1.6.7", commonscli : "1.4", autoValue : "1.10.2", autoService : "1.1.1", @@ -118,7 +118,7 @@ def test = [ springBeans : "org.springframework:spring-beans:5.3.7", springContext : "org.springframework:spring-context:5.3.7", grpcCore : "io.grpc:grpc-core:1.15.1", // Should upgrade, but this matches our guava version - mockito : "org.mockito:mockito-core:5.12.0", + mockito : "org.mockito:mockito-core:5.13.0", javaxAnnotationApi : "javax.annotation:javax.annotation-api:1.3.2", assertJ : "org.assertj:assertj-core:3.23.1", ] diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java index 17932cf92c..c686b25f0c 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -1877,9 +1877,39 @@ public void intersectionTypeFromConditionalExprInStringConcat() { @Test public void intersectionTypeInvalidAssign() { - makeHelper() - .addSourceLines( - "Test.java", + String[] source; + // javac behavior differs between versions before and after 23, so we have two versions of the + // test source code + if (Runtime.version().feature() >= 23) { + source = + new String[] { + "package com.uber;", + "import org.jspecify.annotations.Nullable;", + "import java.io.Serializable;", + "public class Test {", + " interface A {}", + " static class B implements A<@Nullable String>, Serializable {}", + " static class C implements A, Serializable {}", + " static void test1(Object o) {", + " var x = (A & Serializable) o;", + " // BUG: Diagnostic contains: Cannot assign from type B to type A & Serializable", + " x = new B();", + " // ok", + " x = new C();", + " }", + " static void test2(Object o) {", + " var x = (A<@Nullable String> & Serializable) o;", + " x = new B();", + " // BUG: Diagnostic contains: Cannot assign from type C to type A<@Nullable String> & Serializable", + " x = new C();", + " }", + "}" + }; + } else { + // Before JDK 23, javac does not compute types with annotations for cast expressions, so the + // test assertions do not work as expected. + source = + new String[] { "package com.uber;", "import org.jspecify.annotations.Nullable;", "import java.io.Serializable;", @@ -1902,8 +1932,10 @@ public void intersectionTypeInvalidAssign() { // TODO: _should_ be an error, see https://github.com/uber/NullAway/issues/1022 " x = new C();", " }", - "}") - .doTest(); + "}" + }; + } + makeHelper().addSourceLines("Test.java", source).doTest(); } @Test