Skip to content

Commit ea80fe8

Browse files
authored
Test on JDK 22 (#992)
Caught a couple small issues and also lets us clean up some stuff in build scripts.
1 parent 1488098 commit ea80fe8

File tree

6 files changed

+61
-45
lines changed

6 files changed

+61
-45
lines changed

buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
}
2121

2222
jacoco {
23-
toolVersion = "0.8.10"
23+
toolVersion = "0.8.12"
2424
}
2525

2626
// Do not generate reports for individual projects
@@ -64,46 +64,47 @@ test {
6464
]
6565
}
6666

67-
// Create a task to test on JDK 21
68-
def testJdk21 = tasks.register("testJdk21", Test) {
69-
onlyIf {
70-
// Only test on JDK 21 when using the latest Error Prone version
71-
deps.versions.errorProneApi == deps.versions.errorProneLatest
72-
}
73-
javaLauncher = javaToolchains.launcherFor {
74-
languageVersion = JavaLanguageVersion.of(21)
75-
}
67+
// Tasks for testing on other JDK versions; see https://jakewharton.com/build-on-latest-java-test-through-lowest-java/
68+
[21, 22].each { majorVersion ->
69+
def jdkTest = tasks.register("testJdk$majorVersion", Test) {
70+
onlyIf {
71+
// Only run when using the latest Error Prone version
72+
deps.versions.errorProneApi == deps.versions.errorProneLatest
73+
}
74+
javaLauncher = javaToolchains.launcherFor {
75+
languageVersion = JavaLanguageVersion.of(majorVersion)
76+
}
7677

77-
description = "Runs the test suite on JDK 21"
78-
group = LifecycleBasePlugin.VERIFICATION_GROUP
78+
description = "Runs the test suite on JDK $majorVersion"
79+
group = LifecycleBasePlugin.VERIFICATION_GROUP
7980

80-
// Copy inputs from normal Test task.
81-
def testTask = tasks.getByName("test")
82-
classpath = testTask.classpath
83-
testClassesDirs = testTask.testClassesDirs
84-
maxHeapSize = "1024m"
85-
// to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer
86-
jvmArgs += [
87-
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
88-
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
89-
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
90-
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
91-
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
92-
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
93-
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
94-
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
95-
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
96-
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
97-
// Accessed by Lombok tests
98-
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
99-
]
100-
}
81+
// Copy inputs from normal Test task.
82+
def testTask = tasks.getByName("test")
83+
classpath = testTask.classpath
84+
testClassesDirs = testTask.testClassesDirs
85+
maxHeapSize = "1024m"
86+
// to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer
87+
jvmArgs += [
88+
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
89+
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
90+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
91+
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
92+
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
93+
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
94+
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
95+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
96+
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
97+
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
98+
// Accessed by Lombok tests
99+
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
100+
]
101+
}
101102

102-
tasks.named('check').configure {
103-
dependsOn testJdk21
103+
tasks.named('check').configure {
104+
dependsOn jdkTest
105+
}
104106
}
105107

106-
107108
// Share the coverage data to be aggregated for the whole product
108109
configurations.create('coverageDataElements') {
109110
visible = false

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test = [
116116
springBeans : "org.springframework:spring-beans:5.3.7",
117117
springContext : "org.springframework:spring-context:5.3.7",
118118
grpcCore : "io.grpc:grpc-core:1.15.1", // Should upgrade, but this matches our guava version
119-
mockito : "org.mockito:mockito-core:5.5.0",
119+
mockito : "org.mockito:mockito-core:5.12.0",
120120
javaxAnnotationApi : "javax.annotation:javax.annotation-api:1.3.2",
121121
assertJ : "org.assertj:assertj-core:3.23.1",
122122
]

jar-infer/jar-infer-lib/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ test {
4646
dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar'
4747
}
4848

49+
tasks.getByName('testJdk22').configure {
50+
// Won't work until WALA supports JDK 22; see https://github.com/wala/WALA/issues/1414
51+
onlyIf { false }
52+
}
53+
4954
tasks.withType(JavaCompile).configureEach {
5055
options.compilerArgs += "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"
5156
}

jdk-recent-unit-tests/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ dependencies {
4343
testModulePath deps.test.cfQual
4444
}
4545

46-
test {
47-
jvmArgs += [
46+
tasks.withType(Test).configureEach { test ->
47+
test.jvmArgs += [
4848
// Expose a module path for tests as a JVM property.
4949
// Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests
5050
"-Dtest.module.path=${configurations.testModulePath.asPath}"

jmh/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ jmh {
128128
// includes = ['DFlowMicro']
129129
}
130130

131-
tasks.named('test') {
131+
tasks.withType(Test).configureEach { test ->
132132
// pass the extra JVM args so we can compile benchmarks in unit tests
133-
jvmArgs += extraJVMArgs
134-
}
135-
136-
tasks.getByName('testJdk21').configure {
137-
jvmArgs += extraJVMArgs
133+
test.jvmArgs += extraJVMArgs
138134
}

nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ private static class DefaultLibraryModels implements LibraryModels {
400400
"com.google.common.base.Preconditions",
401401
"<T>checkNotNull(T,java.lang.String,java.lang.Object...)"),
402402
0)
403+
// For JDK 22
404+
// TODO check if this is still needed in JDK 23 / subsequent releases
405+
.put(
406+
methodRef(
407+
"com.google.common.base.Preconditions",
408+
"<T>checkNotNull(T,java.lang.String,[email protected] Object...)"),
409+
0)
403410
.put(
404411
methodRef(
405412
"com.google.common.base.Preconditions",
@@ -516,6 +523,13 @@ private static class DefaultLibraryModels implements LibraryModels {
516523
"com.google.common.base.Verify",
517524
"<T>verifyNotNull(T,java.lang.String,java.lang.Object...)"),
518525
0)
526+
// For JDK 22
527+
// TODO check if this is still needed in JDK 23 / subsequent releases
528+
.put(
529+
methodRef(
530+
"com.google.common.base.Verify",
531+
"<T>verifyNotNull(T,java.lang.String,[email protected] Object...)"),
532+
0)
519533
.put(methodRef("java.util.Objects", "<T>requireNonNull(T)"), 0)
520534
.put(methodRef("java.util.Objects", "<T>requireNonNull(T,java.lang.String)"), 0)
521535
.put(

0 commit comments

Comments
 (0)