Skip to content

Commit

Permalink
Prepare for JDK 21
Browse files Browse the repository at this point in the history
Added test for null case (covering uber#831) and changed JDK 17 to JDK 21 for unit testing
  • Loading branch information
armughan11 committed Sep 28, 2023
1 parent ab387b9 commit cacadbe
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 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
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
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,30 @@ public void testSwitchExprLambda() {
"}")
.doTest();
}

@Ignore
@Test
public void testSwitchExprNullCase() {
defaultCompilationHelper
.addSourceLines(
"SwitchExpr.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"class SwitchExpr {",
" public enum NullableEnum {",
" a,",
" b,",
" }",
" // NOTE: we should report a bug here for nullableEn but cannot do so until",
" // Error Prone supports matching switch expressions",
" 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 cacadbe

Please sign in to comment.