Skip to content

Commit

Permalink
Compile and test against Error Prone 2.11.0 (#567)
Browse files Browse the repository at this point in the history
This required more significant changes than a typical Error Prone bump, since Error Prone 2.11.0 requires Java 11. To adjust, any build of NullAway on a JDK 11+ JVM now targets Java 11, whereas builds on a JDK 8 JVM still target Java 8. To maintain JDK 8 compatibility in releases, we need to be careful to create the release jars using a JDK 8 VM; the release instructions have been updated appropriately.
  • Loading branch information
msridhar authored Feb 9, 2022
1 parent 9dbdd65 commit e1cae62
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
epVersion: 2.4.0
- os: macos-latest
java: 11
epVersion: 2.10.0
epVersion: 2.11.0
- os: ubuntu-latest
java: 11
epVersion: 2.10.0
epVersion: 2.11.0
- os: windows-latest
java: 11
epVersion: 2.10.0
epVersion: 2.11.0
- os: ubuntu-latest
java: 17
epVersion: 2.10.0
epVersion: 2.11.0
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
5 changes: 5 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
IMPORTANT: Make sure you are using a JDK 8 JVM by checking `java -version` before any
of the steps below. If you run the steps below on a JDK 11+ JVM, that will break Java
8 support, as the released jars will only run on JDK 11. We do not target Java 8 when
building on JDK 11 since Error Prone has required Java 11 since version 2.11.0.

(Recommended, but optional) Update JarInfer Android SDK Models
==============================================================

Expand Down
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,24 @@ subprojects { project ->
}
}

if (JavaVersion.current().java9Compatible) {
// We target Java 11 when building on JDK 11+, but Java 8 when building on JDK 8, since
// EP 2.11.0+ requires Java 11
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
tasks.withType(JavaCompile) {
options.release = 8
java.sourceCompatibility = "11"
java.targetCompatibility = "11"
}
} else {
tasks.withType(JavaCompile) {
java.sourceCompatibility = "1.8"
java.targetCompatibility = "1.8"
}
}

// Ensure we are running on Java 8 whenever publishing to remote repos
tasks.withType(PublishToMavenRepository) {
doFirst {
assert JavaVersion.current() == JavaVersion.VERSION_1_8 : "Only publish to remote repos on JDK 1.8"
}
}

Expand Down
7 changes: 7 additions & 0 deletions code-coverage-report/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ plugins {
id 'com.github.kt3k.coveralls'
}

// Use JDK 17 for this module, via a toolchain. We need JDK 17 since this module
// depends on jdk17-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)

// A resolvable configuration to collect source code
def sourcesPath = configurations.create("sourcesPath") {
visible = false
Expand Down
5 changes: 3 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ if (project.hasProperty("epApiVersion")) {
def versions = [
asm : "7.1",
checkerFramework : "3.21.1",
// The version of Error Prone used to check NullAway's code
errorProne : "2.10.0",
// The version of Error Prone used to check NullAway's code.
// EP 2.10.0 was the last version compatible with Java 8
errorProne : JavaVersion.current() >= JavaVersion.VERSION_11 ? "2.11.0" : "2.10.0",
// The version of Error Prone that NullAway is compiled and tested against
errorProneApi : project.hasProperty("epApiVersion") ? epApiVersion : oldestErrorProneApi,
support : "27.1.1",
Expand Down
3 changes: 0 additions & 3 deletions jar-infer/jar-infer-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id "com.github.johnrengelman.shadow"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ public class JarInferTest {

private CompilationTestHelper compilationTestHelper;

@BugPattern(
name = "DummyChecker",
summary = "Dummy checker to use CompilationTestHelper",
severity = WARNING)
/**
* A dummy checker to allow us to use {@link CompilationTestHelper} to compile Java code for
* testing, as it requires a {@link BugChecker} to run.
*/
@BugPattern(
name = "DummyChecker",
summary = "Dummy checker to use CompilationTestHelper",
severity = WARNING)
@SuppressWarnings("BugPatternNaming") // remove once we require EP 2.11+
public static class DummyChecker extends BugChecker {
public DummyChecker() {}
}
Expand Down
3 changes: 0 additions & 3 deletions jar-infer/nullaway-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ plugins {
id "nullaway.jacoco-conventions"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
testImplementation deps.test.junit4
testImplementation(deps.build.errorProneTestHelpers) {
Expand Down
3 changes: 0 additions & 3 deletions jar-infer/test-java-lib-jarinfer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ plugins {

evaluationDependsOn(":jar-infer:jar-infer-cli")

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

def astubxPath = "com/uber/nullaway/jarinfer/provider/jarinfer.astubx"

jar {
Expand Down
3 changes: 3 additions & 0 deletions jdk17-unit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ plugins {
}

// Use JDK 17 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)

configurations {
Expand Down
24 changes: 19 additions & 5 deletions nullaway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ plugins {
id 'nullaway.jacoco-conventions'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

configurations {
nullawayJar
}
Expand Down Expand Up @@ -92,9 +89,26 @@ test {

apply plugin: 'com.vanniktech.maven.publish'

// Create a task to build NullAway with NullAway checking enabled
// For some reason, this doesn't work on Java 8
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
// Required on Java 11+ since Error Prone and NullAway access a bunch of
// JDK-internal APIs that are not exposed otherwise
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.source.tree=ALL-UNNAMED",
]
}
// Create a task to build NullAway with NullAway checking enabled
// For some reason, this doesn't work on Java 8
tasks.register('buildWithNullAway', JavaCompile) {
// Configure compilation to run with Error Prone and NullAway
source = sourceSets.main.java
Expand Down
1 change: 1 addition & 0 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
summary = "Nullability type error.",
tags = BugPattern.StandardTags.LIKELY_ERROR,
severity = WARNING)
@SuppressWarnings("BugPatternNaming") // remove once we require EP 2.11+
public class NullAway extends BugChecker
implements BugChecker.MethodInvocationTreeMatcher,
BugChecker.AssignmentTreeMatcher,
Expand Down
3 changes: 0 additions & 3 deletions sample-library-model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ plugins {
id "java-library"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
compileOnly deps.apt.autoService
annotationProcessor deps.apt.autoService
Expand Down
3 changes: 0 additions & 3 deletions test-library-models/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ plugins {
id "java-library"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
compileOnly deps.apt.autoService
annotationProcessor deps.apt.autoService
Expand Down

0 comments on commit e1cae62

Please sign in to comment.