Skip to content

Commit

Permalink
Run recent JDK tests on JDK 21 (#834)
Browse files Browse the repository at this point in the history
Added test for null case in switch statements (covering #831) and
changed JDK 17 to JDK 21 for testing recent language features

---------

Co-authored-by: Manu Sridharan <[email protected]>
  • Loading branch information
armughan11 and msridhar authored Sep 28, 2023
1 parent ab387b9 commit d04828a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
8 changes: 4 additions & 4 deletions code-coverage-report/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ plugins {
id 'jacoco'
}

// Use JDK 17 for this module, via a toolchain. We need JDK 17 since this module
// depends on jdk17-unit-tests.
// Use JDK 21 for this module, via a toolchain. We need JDK 21 since this module
// depends on jdk-recent-unit-tests.
// We must null out sourceCompatibility and targetCompatibility to use toolchains.
java.sourceCompatibility = null
java.targetCompatibility = null
java.toolchain.languageVersion.set JavaLanguageVersion.of(17)
java.toolchain.languageVersion.set JavaLanguageVersion.of(21)

// A resolvable configuration to collect source code
def sourcesPath = configurations.create("sourcesPath") {
Expand Down Expand Up @@ -79,5 +79,5 @@ dependencies {
implementation project(':jar-infer:jar-infer-lib')
implementation project(':jar-infer:nullaway-integration-test')
implementation project(':guava-recent-unit-tests')
implementation project(':jdk17-unit-tests')
implementation project(':jdk-recent-unit-tests')
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ plugins {
id 'nullaway.java-test-conventions'
}

// Use JDK 17 for this module, via a toolchain
// Use JDK 21 for this module, via a toolchain
// We must null out sourceCompatibility and targetCompatibility to use toolchains.
java.sourceCompatibility = null
java.targetCompatibility = null
java.toolchain.languageVersion.set JavaLanguageVersion.of(17)
java.toolchain.languageVersion.set JavaLanguageVersion.of(21)

configurations {
// We use this configuration to expose a module path that can be
Expand Down Expand Up @@ -52,9 +52,6 @@ test {
}

tasks.getByName('testJdk21').configure {
jvmArgs += [
// Expose a module path for tests as a JVM property.
// Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests
"-Dtest.module.path=${configurations.testModulePath.asPath}"
]
// We don't need this task since we already run the tests on JDK 21
onlyIf { false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.uber.nullaway.NullAway;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -174,4 +175,28 @@ public void testSwitchExprLambda() {
"}")
.doTest();
}

@Ignore("requires fix for crash in Checker dataflow library")
@Test
public void testSwitchExprNullCase() {
defaultCompilationHelper
.addSourceLines(
"SwitchExpr.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"class SwitchExpr {",
" public enum NullableEnum {",
" A,",
" B,",
" }",
" static Object handleNullableEnum(@Nullable NullableEnum nullableEnum) {",
" return switch (nullableEnum) {",
" case A -> new Object();",
" case B -> new Object();",
" case null -> throw new IllegalArgumentException(\"NullableEnum parameter is required\");",
" };",
" }",
"}")
.doTest();
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include ':jar-infer:test-java-lib-jarinfer'
include ':jar-infer:nullaway-integration-test'
include ':jmh'
include ':guava-recent-unit-tests'
include ':jdk17-unit-tests'
include ':jdk-recent-unit-tests'
include ':code-coverage-report'
include ':sample-app'
include ':jar-infer:test-android-lib-jarinfer'

0 comments on commit d04828a

Please sign in to comment.