From ce971d5008cf9e385370105441d962a7dda92104 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 7 Oct 2023 16:58:21 -0700 Subject: [PATCH 1/5] WIP --- .github/workflows/continuous-integration.yml | 4 ++-- gradle/dependencies.gradle | 4 ++-- guava-recent-unit-tests/build.gradle | 2 +- nullaway/build.gradle | 13 +------------ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 124952f36c..ec47cd2c4f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -15,10 +15,10 @@ jobs: include: - os: ubuntu-latest java: 11 - epVersion: 2.4.0 + epVersion: 2.10.0 - os: ubuntu-latest java: 17 - epVersion: 2.4.0 + epVersion: 2.10.0 - os: macos-latest java: 11 epVersion: 2.22.0 diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index e31eb389e8..0e295a96fb 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -17,7 +17,7 @@ import org.gradle.util.VersionNumber */ // The oldest version of Error Prone that we support running on -def oldestErrorProneVersion = "2.4.0" +def oldestErrorProneVersion = "2.10.0" // Latest released Error Prone version that we've tested with def latestErrorProneVersion = "2.22.0" // Default to using latest tested Error Prone version @@ -72,7 +72,7 @@ def build = [ errorProneJavac : "com.google.errorprone:javac:9+181-r4173-1", errorProneTestHelpers : "com.google.errorprone:error_prone_test_helpers:${versions.errorProneApi}", checkerDataflow : "org.checkerframework:dataflow-nullaway:${versions.checkerFramework}", - guava : "com.google.guava:guava:24.1.1-jre", + guava : "com.google.guava:guava:30.1-jre", javaxValidation : "javax.validation:validation-api:2.0.1.Final", jspecify : "org.jspecify:jspecify:0.3.0", jsr305Annotations : "com.google.code.findbugs:jsr305:3.0.2", diff --git a/guava-recent-unit-tests/build.gradle b/guava-recent-unit-tests/build.gradle index 4d78ac52a3..7740123bba 100644 --- a/guava-recent-unit-tests/build.gradle +++ b/guava-recent-unit-tests/build.gradle @@ -35,7 +35,7 @@ dependencies { def jdk8Test = tasks.register("testJdk8", Test) { onlyIf { // Only if we are using a version of Error Prone compatible with JDK 8 - deps.versions.errorProneApi == "2.4.0" + deps.versions.errorProneApi == "2.10.0" } javaLauncher = javaToolchains.launcherFor { diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 83f7e62e21..8000dbc9e3 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -70,17 +70,6 @@ javadoc { failOnError = false } - -test { - if (deps.versions.errorProneApi == "2.4.0" && JavaVersion.current() >= JavaVersion.VERSION_17) { - // This test does not pass on JDK 17 with Error Prone 2.4.0 due to a Mockito incompatibility. Skip it (the - // test passes with more recent Error Prone versions on JDK 17) - filter { - excludeTestsMatching "com.uber.nullaway.NullAwaySerializationTest.suggestNullableArgumentOnBytecodeNoFileInfo" - } - } -} - apply plugin: 'com.vanniktech.maven.publish' // These --add-exports arguments are required when targeting JDK 11+ since Error Prone and NullAway access a bunch of @@ -107,7 +96,7 @@ apply plugin: 'com.vanniktech.maven.publish' def jdk8Test = tasks.register("testJdk8", Test) { onlyIf { // Only if we are using a version of Error Prone compatible with JDK 8 - deps.versions.errorProneApi == "2.4.0" + deps.versions.errorProneApi == "2.10.0" } javaLauncher = javaToolchains.launcherFor { From e7a27cc8ff5f41a18d14e069ec9e89e8ce0becca Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 7 Oct 2023 17:03:35 -0700 Subject: [PATCH 2/5] cleanup --- .../NullAwayAutoSuggestNoCastTest.java | 39 +------------------ .../nullaway/NullAwayAutoSuggestTest.java | 21 +--------- 2 files changed, 3 insertions(+), 57 deletions(-) diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestNoCastTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestNoCastTest.java index 4ed879279f..1817d25f84 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestNoCastTest.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestNoCastTest.java @@ -23,8 +23,6 @@ package com.uber.nullaway; import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.ErrorProneFlags; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -36,54 +34,21 @@ public class NullAwayAutoSuggestNoCastTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private ErrorProneFlags flagsWithAutoFixSuppressionComment; - - private ErrorProneFlags flagsNoAutoFixSuppressionComment; - - @Before - public void setup() { - // With AutoFixSuppressionComment - ErrorProneFlags.Builder b = ErrorProneFlags.builder(); - b.putFlag("NullAway:AnnotatedPackages", "com.uber,com.ubercab,io.reactivex"); - b.putFlag("NullAway:SuggestSuppressions", "true"); - b.putFlag("NullAway:AutoFixSuppressionComment", "PR #000000"); - flagsWithAutoFixSuppressionComment = b.build(); - // Without AutoFixSuppressionComment - b = ErrorProneFlags.builder(); - b.putFlag("NullAway:AnnotatedPackages", "com.uber,com.ubercab,io.reactivex"); - b.putFlag("NullAway:SuggestSuppressions", "true"); - flagsNoAutoFixSuppressionComment = b.build(); - } - - // In EP 2.6.0 the newInstance() method we use below is deprecated. We cannot currently address - // the warning since the replacement method was only added in EP 2.5.1, and we still want to - // support EP 2.4.0. So, we suppress the warning for now - @SuppressWarnings("deprecation") private BugCheckerRefactoringTestHelper makeTestHelperWithSuppressionComment() { - return BugCheckerRefactoringTestHelper.newInstance( - new NullAway(flagsWithAutoFixSuppressionComment), getClass()) + return BugCheckerRefactoringTestHelper.newInstance(NullAway.class, getClass()) .setArgs( "-d", temporaryFolder.getRoot().getAbsolutePath(), - // the remaining args are not needed right now, but they will be necessary when we - // switch to the more modern newInstance() API "-XepOpt:NullAway:AnnotatedPackages=com.uber,com.ubercab,io.reactivex", "-XepOpt:NullAway:SuggestSuppressions=true", "-XepOpt:NullAway:AutoFixSuppressionComment=PR #000000"); } - // In EP 2.6.0 the newInstance() method we use below is deprecated. We cannot currently address - // the warning since the replacement method was only added in EP 2.5.1, and we still want to - // support EP 2.4.0. So, we suppress the warning for now - @SuppressWarnings("deprecation") private BugCheckerRefactoringTestHelper makeTestHelper() { - return BugCheckerRefactoringTestHelper.newInstance( - new NullAway(flagsNoAutoFixSuppressionComment), getClass()) + return BugCheckerRefactoringTestHelper.newInstance(NullAway.class, getClass()) .setArgs( "-d", temporaryFolder.getRoot().getAbsolutePath(), - // the remaining args are not needed right now, but they will be necessary when we - // switch to the more modern newInstance() API "-XepOpt:NullAway:AnnotatedPackages=com.uber,com.ubercab,io.reactivex", "-XepOpt:NullAway:SuggestSuppressions=true"); } diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestTest.java index 03ae7e35a3..ba5eabea27 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestTest.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayAutoSuggestTest.java @@ -25,11 +25,9 @@ import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.ErrorProneFlags; import com.sun.source.tree.Tree; import com.uber.nullaway.testlibrarymodels.TestLibraryModels; import java.io.IOException; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -41,30 +39,13 @@ public class NullAwayAutoSuggestTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private ErrorProneFlags flags; - - @Before - public void setup() { - ErrorProneFlags.Builder b = ErrorProneFlags.builder(); - b.putFlag("NullAway:AnnotatedPackages", "com.uber,com.ubercab,io.reactivex"); - b.putFlag("NullAway:CastToNonNullMethod", "com.uber.nullaway.testdata.Util.castToNonNull"); - b.putFlag("NullAway:SuggestSuppressions", "true"); - flags = b.build(); - } - - // In EP 2.6.0 the newInstance() method we use below is deprecated. We cannot currently address - // the warning since the replacement method was only added in EP 2.5.1, and we still want to - // support EP 2.4.0. So, we suppress the warning for now - @SuppressWarnings("deprecation") private BugCheckerRefactoringTestHelper makeTestHelper() { - return BugCheckerRefactoringTestHelper.newInstance(new NullAway(flags), getClass()) + return BugCheckerRefactoringTestHelper.newInstance(NullAway.class, getClass()) .setArgs( "-d", temporaryFolder.getRoot().getAbsolutePath(), "-processorpath", TestLibraryModels.class.getProtectionDomain().getCodeSource().getLocation().getPath(), - // the remaining args are not needed right now, but they will be necessary when we - // switch to the more modern newInstance() API "-XepOpt:NullAway:AnnotatedPackages=com.uber,com.ubercab,io.reactivex", "-XepOpt:NullAway:CastToNonNullMethod=com.uber.nullaway.testdata.Util.castToNonNull", "-XepOpt:NullAway:SuggestSuppressions=true"); From bc3eb329ec3488a91c9c5341249f24ec8f358530 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sun, 8 Oct 2023 10:51:45 -0700 Subject: [PATCH 3/5] Pass on README --- README.md | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 41d6e21f64..2fd766b34d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ NullAway is *fast*. It is built as a plugin to [Error Prone](http://errorprone. ### Overview -NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.4.0 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems. +NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.10.0 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems. ### Gradle @@ -19,19 +19,18 @@ To integrate NullAway into your non-Android Java project, add the following to y ```gradle plugins { // we assume you are already using the Java plugin - id "net.ltgt.errorprone" version "0.6" + id "net.ltgt.errorprone" version "" } dependencies { - annotationProcessor "com.uber.nullaway:nullaway:0.10.13" + errorprone "com.uber.nullaway:nullaway:" // Optional, some source of nullability annotations. // Not required on Android if you use the support // library nullability annotations. compileOnly "com.google.code.findbugs:jsr305:3.0.2" - errorprone "com.google.errorprone:error_prone_core:2.4.0" - errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" + errorprone "com.google.errorprone:error_prone_core:" } import net.ltgt.gradle.errorprone.CheckSeverity @@ -47,23 +46,11 @@ tasks.withType(JavaCompile) { } ``` -Let's walk through this script step by step. The `plugins` section pulls in the [Gradle Error Prone plugin](https://github.com/tbroyer/gradle-errorprone-plugin) for Error Prone integration. If you are using the older `apply plugin` syntax instead of a `plugins` block, the following is equivalent: -```gradle -buildscript { - repositories { - gradlePluginPortal() - } - dependencies { - classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.6" - } -} - -apply plugin: 'net.ltgt.errorprone' -``` +Let's walk through this script step by step. The `plugins` section pulls in the [Gradle Error Prone plugin](https://github.com/tbroyer/gradle-errorprone-plugin) for Error Prone integration. -In `dependencies`, the `annotationProcessor` line loads NullAway, and the `compileOnly` line loads a [JSR 305](https://jcp.org/en/jsr/detail?id=305) library which provides a suitable `@Nullable` annotation (`javax.annotation.Nullable`). NullAway allows for any `@Nullable` annotation to be used, so, e.g., `@Nullable` from the Android Support Library or JetBrains annotations is also fine. The `errorprone` line ensures that a compatible version of Error Prone is used, and the `errorproneJavac` line is needed for JDK 8 compatibility. +In `dependencies`, the first `errorprone` line loads NullAway, and the `compileOnly` line loads a [JSR 305](https://jcp.org/en/jsr/detail?id=305) library which provides a suitable `@Nullable` annotation (`javax.annotation.Nullable`). NullAway allows for any `@Nullable` annotation to be used, so, e.g., `@Nullable` from the Android Support Library or JetBrains annotations is also fine. The second `errorprone` line sets the version of Error Prone is used. -Finally, in the `tasks.withType(JavaCompile)` section, we pass some configuration options to NullAway. First `check("NullAway", CheckSeverity.ERROR)` sets NullAway issues to the error level (it's equivalent to the `-Xep:NullAway:ERROR` standard Error Prone argument); by default NullAway emits warnings. Then, `option("NullAway:AnnotatedPackages", "com.uber")` (equivalent to the `-XepOpt:NullAway:AnnotatedPackages=com.uber` standard Error Prone argument), tells NullAway that source code in packages under the `com.uber` namespace should be checked for null dereferences and proper usage of `@Nullable` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable` (see [the docs](https://github.com/uber/NullAway/wiki/Configuration) for more detail). NullAway requires at least the `AnnotatedPackages` configuration argument to run, in order to distinguish between annotated and unannotated code. See [the configuration docs](https://github.com/uber/NullAway/wiki/Configuration) for other useful configuration options. +Finally, in the `tasks.withType(JavaCompile)` section, we pass some configuration options to NullAway. First `check("NullAway", CheckSeverity.ERROR)` sets NullAway issues to the error level (it's equivalent to the `-Xep:NullAway:ERROR` standard Error Prone argument); by default NullAway emits warnings. Then, `option("NullAway:AnnotatedPackages", "com.uber")` (equivalent to the `-XepOpt:NullAway:AnnotatedPackages=com.uber` standard Error Prone argument) tells NullAway that source code in packages under the `com.uber` namespace should be checked for null dereferences and proper usage of `@Nullable` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable` (see [the docs](https://github.com/uber/NullAway/wiki/Configuration) for more detail). NullAway requires at least the `AnnotatedPackages` configuration argument to run, in order to distinguish between annotated and unannotated code. See [the configuration docs](https://github.com/uber/NullAway/wiki/Configuration) for other useful configuration options. We recommend addressing all the issues that Error Prone reports, particularly those reported as errors (rather than warnings). But, if you'd like to try out NullAway without running other Error Prone checks, you can use `options.errorprone.disableAllChecks` (equivalent to passing `"-XepDisableAllChecks"` to the compiler, before the NullAway-specific arguments). @@ -75,12 +62,11 @@ The configuration for an Android project is very similar to the Java case, with ```gradle dependencies { - annotationProcessor "com.uber.nullaway:nullaway:0.10.13" - errorprone "com.google.errorprone:error_prone_core:2.4.0" - errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" + errorprone "com.uber.nullaway:nullaway:" + errorprone "com.google.errorprone:error_prone_core:" } ``` -A complete Android `build.gradle` example is [here](https://gist.github.com/msridhar/6cacd429567f1d1ad9a278e06809601c). Also see our [sample app](https://github.com/uber/NullAway/blob/master/sample-app/). (The sample app's [`build.gradle`](https://github.com/uber/NullAway/blob/master/sample-app/) is not suitable for direct copy-pasting, as some configuration is inherited from the top-level `build.gradle`.) +For a more complete example see our [sample app](https://github.com/uber/NullAway/blob/master/sample-app/). (The sample app's [`build.gradle`](https://github.com/uber/NullAway/blob/master/sample-app/) is not suitable for direct copy-pasting, as some configuration is inherited from the top-level `build.gradle`.) #### Annotation Processors / Generated Code From cdb287b97843f58e329230a04dc389c2fc311bea Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sun, 8 Oct 2023 10:54:18 -0700 Subject: [PATCH 4/5] Mention Gradle NullAway plugin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fd766b34d..13769974d7 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Let's walk through this script step by step. The `plugins` section pulls in the In `dependencies`, the first `errorprone` line loads NullAway, and the `compileOnly` line loads a [JSR 305](https://jcp.org/en/jsr/detail?id=305) library which provides a suitable `@Nullable` annotation (`javax.annotation.Nullable`). NullAway allows for any `@Nullable` annotation to be used, so, e.g., `@Nullable` from the Android Support Library or JetBrains annotations is also fine. The second `errorprone` line sets the version of Error Prone is used. -Finally, in the `tasks.withType(JavaCompile)` section, we pass some configuration options to NullAway. First `check("NullAway", CheckSeverity.ERROR)` sets NullAway issues to the error level (it's equivalent to the `-Xep:NullAway:ERROR` standard Error Prone argument); by default NullAway emits warnings. Then, `option("NullAway:AnnotatedPackages", "com.uber")` (equivalent to the `-XepOpt:NullAway:AnnotatedPackages=com.uber` standard Error Prone argument) tells NullAway that source code in packages under the `com.uber` namespace should be checked for null dereferences and proper usage of `@Nullable` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable` (see [the docs](https://github.com/uber/NullAway/wiki/Configuration) for more detail). NullAway requires at least the `AnnotatedPackages` configuration argument to run, in order to distinguish between annotated and unannotated code. See [the configuration docs](https://github.com/uber/NullAway/wiki/Configuration) for other useful configuration options. +Finally, in the `tasks.withType(JavaCompile)` section, we pass some configuration options to NullAway. First `check("NullAway", CheckSeverity.ERROR)` sets NullAway issues to the error level (it's equivalent to the `-Xep:NullAway:ERROR` standard Error Prone argument); by default NullAway emits warnings. Then, `option("NullAway:AnnotatedPackages", "com.uber")` (equivalent to the `-XepOpt:NullAway:AnnotatedPackages=com.uber` standard Error Prone argument) tells NullAway that source code in packages under the `com.uber` namespace should be checked for null dereferences and proper usage of `@Nullable` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable` (see [the docs](https://github.com/uber/NullAway/wiki/Configuration) for more detail). NullAway requires at least the `AnnotatedPackages` configuration argument to run, in order to distinguish between annotated and unannotated code. See [the configuration docs](https://github.com/uber/NullAway/wiki/Configuration) for other useful configuration options. For even simpler configuration of NullAway options, use the [Gradle NullAway plugin](https://github.com/tbroyer/gradle-nullaway-plugin). We recommend addressing all the issues that Error Prone reports, particularly those reported as errors (rather than warnings). But, if you'd like to try out NullAway without running other Error Prone checks, you can use `options.errorprone.disableAllChecks` (equivalent to passing `"-XepDisableAllChecks"` to the compiler, before the NullAway-specific arguments). From f708a1a700fde08fd9de70894fa57bb459a581ed Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sun, 8 Oct 2023 11:45:28 -0700 Subject: [PATCH 5/5] Update releasing instructions --- RELEASING.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/RELEASING.md b/RELEASING.md index e9635dbf34..cecfedf6a2 100755 --- a/RELEASING.md +++ b/RELEASING.md @@ -29,12 +29,11 @@ Releasing 1. Change the version in `gradle.properties` to a non-SNAPSHOT version. 2. Update the `CHANGELOG.md` for the impending release. - 3. Update the `README.md` with the new version. - 4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) - 5. `git tag -a vX.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) - 6. `./gradlew clean publish` - 7. Update the `gradle.properties` to the next SNAPSHOT version. - 8. `git commit -am "Prepare next development version."` - 9. `git push && git push --tags` - 10. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. - 11. Go to [this page](https://github.com/uber/NullAway/releases/new) to create a new release on GitHub, using the release notes from `CHANGELOG.md`. + 3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) + 4. `git tag -a vX.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) + 5. `./gradlew clean publish` + 6. Update the `gradle.properties` to the next SNAPSHOT version. + 7. `git commit -am "Prepare next development version."` + 8. `git push && git push --tags` + 9. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. + 10. Go to [this page](https://github.com/uber/NullAway/releases/new) to create a new release on GitHub, using the release notes from `CHANGELOG.md`.