-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to JSpecify 1.0 and use JSpecify annotations in NullAway code #1000
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1000 +/- ##
=========================================
Coverage 85.95% 85.95%
Complexity 2073 2073
=========================================
Files 83 83
Lines 6873 6873
Branches 1322 1322
=========================================
Hits 5908 5908
Misses 551 551
Partials 414 414 ☔ View full report in Codecov by Sentry. |
@cpovirk could I ask you to look over the changes in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
README.md
Outdated
@@ -58,7 +58,7 @@ We recommend addressing all the issues that Error Prone reports, particularly th | |||
|
|||
Versions 3.0.0 and later of the Gradle Error Prone Plugin [no longer support Android](https://github.com/tbroyer/gradle-errorprone-plugin/releases/tag/v3.0.0). So if you're using a recent version of this plugin, you'll need to add some further configuration to run Error Prone and NullAway. Our [sample app `build.gradle` file](https://github.com/uber/NullAway/blob/master/sample-app/build.gradle) shows one way to do this, but your Android project may require tweaks. Alternately, 2.x versions of the Gradle Error Prone Plugin still support Android and may still work with your project. | |||
|
|||
Beyond that, compared to the Java configuration, the `com.google.code.findbugs:jsr305:3.0.2` dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library instead. | |||
Beyond that, compared to the Java configuration, the JSpecify dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpovirk are we currently encouraging Android users to switch over from Android support annotations to JSpecify as well? Or will that cause problems for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phrasing is difficult :) We have had similar conversations internally.
On the one hand, it would be nice if we could find a way to avoid implying that the Android annotations (which of course are declaration annotations) are "just as good" as the JSpecify ones.
On the other hand, it would be nice to make clear there there are still tradeoffs, by which I mainly mean "Dagger (if you don't use a recent javac)." (On the plus side, maybe Android users can more upgrade their compiler especially easily, since they don't need to worry about setting --release
? Part of me now wants for the NullAway docs to demonstrate configuring a Java 22 toolchain for Android, except that it's not really fair to put that on the critical path for NullAway adopters :))
I was hoping to convince myself that we had an existing doc that covered this, but as you saw, I ended up leaving a comment on a JSpecify issue instead.
The best link at this point is probably https://jspecify.dev/docs/whether/#annotation-processors. Let me see if I can think of a way that I'd phrase that once I get back to my desk after a quick break. I'm hoping to propose a different framing for this sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought: I might be putting too much emphasis on the ability to annotate type arguments, type-parameter bounds, and array-element types yet, since NullAway support there is still developing. (And of course NullAway already offers a way to treat unannotated types as non-nullable when you want it, so there's less reason for @NullMarked
, too.)
I think I'd probably just keep this as you have it for now, and we can revisit once we have docs that speak more directly to the tradeoffs. Maybe we'll also tweak the comment in the code block at line 29 at that point.
Hmm, but now that I'm here: Nowadays, people use androidx.annotation.Nullable
instead of android.support.annotation.Nullable
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will switch to refer to androidx
, thanks!
@@ -31,7 +31,8 @@ dependencies { | |||
annotationProcessor deps.apt.autoValue | |||
compileOnly deps.apt.autoServiceAnnot | |||
annotationProcessor deps.apt.autoService | |||
compileOnly deps.build.jsr305Annotations | |||
// Using api following the guidance at https://jspecify.dev/docs/using#gradle | |||
api deps.build.jspecify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpovirk this is encouraged, correct? This will bring in the JSpecify jar onto the annotation processor path for users, but they will have it there anyway I think if they are using a recent version of Error Prone. I think this could only cause a problem if for some reason they already have a dep on an old version of the JSpecify jar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about Error Prone, too. All I've found there so far is a test dep, but it could have missed a full dep, especially since I didn't look at all at indirect deps. (So someday Error Prone will get it through Guava or Caffeine or whatever.)
I think that including it should be fine. I think you're right that there could in theory be trouble if some other annotation processor wanted the old package, but that seems very unlikely, and things would generally work out OK even in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error Prone will have the dep in 2.30.0 (or 2.29.3 or whatever the next release after 2.29.2 is):
README.md
Outdated
@@ -58,7 +58,7 @@ We recommend addressing all the issues that Error Prone reports, particularly th | |||
|
|||
Versions 3.0.0 and later of the Gradle Error Prone Plugin [no longer support Android](https://github.com/tbroyer/gradle-errorprone-plugin/releases/tag/v3.0.0). So if you're using a recent version of this plugin, you'll need to add some further configuration to run Error Prone and NullAway. Our [sample app `build.gradle` file](https://github.com/uber/NullAway/blob/master/sample-app/build.gradle) shows one way to do this, but your Android project may require tweaks. Alternately, 2.x versions of the Gradle Error Prone Plugin still support Android and may still work with your project. | |||
|
|||
Beyond that, compared to the Java configuration, the `com.google.code.findbugs:jsr305:3.0.2` dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library instead. | |||
Beyond that, compared to the Java configuration, the JSpecify dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought: I might be putting too much emphasis on the ability to annotate type arguments, type-parameter bounds, and array-element types yet, since NullAway support there is still developing. (And of course NullAway already offers a way to treat unannotated types as non-nullable when you want it, so there's less reason for @NullMarked
, too.)
I think I'd probably just keep this as you have it for now, and we can revisit once we have docs that speak more directly to the tradeoffs. Maybe we'll also tweak the comment in the code block at line 29 at that point.
Hmm, but now that I'm here: Nowadays, people use androidx.annotation.Nullable
instead of android.support.annotation.Nullable
, right?
@@ -31,7 +31,8 @@ dependencies { | |||
annotationProcessor deps.apt.autoValue | |||
compileOnly deps.apt.autoServiceAnnot | |||
annotationProcessor deps.apt.autoService | |||
compileOnly deps.build.jsr305Annotations | |||
// Using api following the guidance at https://jspecify.dev/docs/using#gradle | |||
api deps.build.jspecify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about Error Prone, too. All I've found there so far is a test dep, but it could have missed a full dep, especially since I didn't look at all at indirect deps. (So someday Error Prone will get it through Guava or Caffeine or whatever.)
I think that including it should be fine. I think you're right that there could in theory be trouble if some other annotation processor wanted the old package, but that seems very unlikely, and things would generally work out OK even in that case.
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.tukaani:xz](https://tukaani.org/xz/java.html) ([source](https://github.com/tukaani-project/xz-java)) | compile | minor | `1.9` -> `1.10` | | [org.eclipse:yasson](https://projects.eclipse.org/projects/ee4j.yasson) ([source](https://github.com/eclipse-ee4j/yasson)) | compile | patch | `3.0.3` -> `3.0.4` | | [org.eclipse.parsson:parsson](https://github.com/eclipse-ee4j/parsson) | compile | patch | `1.1.6` -> `1.1.7` | | [com.uber.nullaway:nullaway](https://github.com/uber/NullAway) | | patch | `0.11.0` -> `0.11.1` | | [io.hosuaby:inject-resources-junit-jupiter](https://github.com/hosuaby/inject-resources) | test | patch | `0.3.3` -> `0.3.5` | | [org.codehaus.mojo:exec-maven-plugin](https://www.mojohaus.org/exec-maven-plugin) ([source](https://github.com/mojohaus/exec-maven-plugin)) | build | minor | `3.3.0` -> `3.4.0` | --- ### Release Notes <details> <summary>tukaani-project/xz-java</summary> ### [`v1.10`](https://github.com/tukaani-project/xz-java/releases/tag/v1.10): XZ for Java 1.10 [Compare Source](tukaani-project/xz-java@v1.9...v1.10) </details> <details> <summary>eclipse-ee4j/yasson</summary> ### [`v3.0.4`](eclipse-ee4j/yasson@3.0.3...3.0.4) [Compare Source](eclipse-ee4j/yasson@3.0.3...3.0.4) </details> <details> <summary>eclipse-ee4j/parsson</summary> ### [`v1.1.7`](eclipse-ee4j/parsson@1.1.6...1.1.7) [Compare Source](eclipse-ee4j/parsson@1.1.6...1.1.7) </details> <details> <summary>uber/NullAway</summary> ### [`v0.11.1`](https://github.com/uber/NullAway/blob/HEAD/CHANGELOG.md#Version-0111) [Compare Source](uber/NullAway@v0.11.0...v0.11.1) - Fix issue 1008 ([#​1009](uber/NullAway#1009)) - JSpecify: read upper bound annotations from bytecode and add tests ([#​1004](uber/NullAway#1004)) - Fix crash with suggested suppressions in JSpecify mode ([#​1001](uber/NullAway#1001)) - Update to JSpecify 1.0 and use JSpecify annotations in NullAway code ([#​1000](uber/NullAway#1000)) - Expose [@​EnsuresNonNull](https://github.com/EnsuresNonNull) and [@​RequiresNonNull](https://github.com/RequiresNonNull) in annotations package ([#​999](uber/NullAway#999)) - Don't report initializer warnings on [@​NullUnmarked](https://github.com/NullUnmarked) constructors / methods ([#​997](uber/NullAway#997)) - Strip annotations from MethodSymbol strings ([#​993](uber/NullAway#993)) - JSpecify: fix crashes where declared parameter / return types were raw ([#​989](uber/NullAway#989)) - JSpecify: Handle [@​nullable](https://github.com/nullable) elements for enhanced-for-loops on arrays ([#​986](uber/NullAway#986)) - Features/944 tidy stream nullability propagator ([#​985](uber/NullAway#985)) - Tests for loops over arrays ([#​982](uber/NullAway#982)) - Bug fixes for array subtyping at returns / parameter passing ([#​980](uber/NullAway#980)) - JSpecify: Handle [@​nonnull](https://github.com/nonnull) elements in [@​nullable](https://github.com/nullable) content arrays ([#​963](uber/NullAway#963)) - Don't report [@​nullable](https://github.com/nullable) type argument errors for unmarked classes ([#​958](uber/NullAway#958)) - External Library Models: Adding support for Nullable upper bounds of Generic Type parameters ([#​949](uber/NullAway#949)) - Refactoring / code cleanups: - Test on JDK 22 ([#​992](uber/NullAway#992)) - Add test case for [@​nullable](https://github.com/nullable) Void with override in JSpecify mode ([#​990](uber/NullAway#990)) - Enable UnnecessaryFinal and PreferredInterfaceType EP checks ([#​991](uber/NullAway#991)) - Add missing [@​test](https://github.com/test) annotation ([#​988](uber/NullAway#988)) - Fix typo in variable name ([#​987](uber/NullAway#987)) - Remove AbstractConfig class ([#​974](uber/NullAway#974)) - Fix Javadoc for MethodRef ([#​973](uber/NullAway#973)) - Refactored data clumps with the help of LLMs (research project) ([#​960](uber/NullAway#960)) - Build / CI tooling maintenance: - Various cleanups enabled by bumping minimum Java and Error Prone versions ([#​962](uber/NullAway#962)) - Disable publishing of snapshot builds from CI ([#​967](uber/NullAway#967)) - Update Gradle action usage in CI workflow ([#​969](uber/NullAway#969)) - Update Gradle config to always compile Java code using JDK 17 ([#​971](uber/NullAway#971)) - Update JavaParser to 3.26.0 ([#​970](uber/NullAway#970)) - Reenable JMH benchmarking in a safer manner ([#​975](uber/NullAway#975)) - Updated JMH Benchmark Comment Action ([#​976](uber/NullAway#976)) - Update to Gradle 8.8 ([#​981](uber/NullAway#981)) - Update to Error Prone 2.28.0 ([#​984](uber/NullAway#984)) - Update to Gradle 8.9 ([#​998](uber/NullAway#998)) - Update to WALA 1.6.6 ([#​1003](uber/NullAway#1003)) </details> <details> <summary>hosuaby/inject-resources</summary> ### [`v0.3.5`](hosuaby/inject-resources@v0.3.4...v0.3.5) [Compare Source](hosuaby/inject-resources@v0.3.4...v0.3.5) ### [`v0.3.4`](hosuaby/inject-resources@v0.3.3...v0.3.4) [Compare Source](hosuaby/inject-resources@v0.3.3...v0.3.4) </details> <details> <summary>mojohaus/exec-maven-plugin</summary> ### [`v3.4.0`](https://github.com/mojohaus/exec-maven-plugin/releases/tag/3.4.0) [Compare Source](mojohaus/exec-maven-plugin@3.3.0...3.4.0) <!-- Optional: add a release summary here --> #### 🚀 New features and improvements - Allow `<includePluginDependencies>` to be specified for the exec:exec goal ([#​432](mojohaus/exec-maven-plugin#432)) [@​sebthom](https://github.com/sebthom) #### 🐛 Bug Fixes - Do not get UPPERCASE env vars ([#​427](mojohaus/exec-maven-plugin#427)) [@​wheezil](https://github.com/wheezil) #### 📦 Dependency updates - Bump org.codehaus.mojo:mojo-parent from 82 to 84 ([#​434](mojohaus/exec-maven-plugin#434)) [@​dependabot](https://github.com/dependabot) - Bump org.codehaus.plexus:plexus-xml from 3.0.0 to 3.0.1 ([#​431](mojohaus/exec-maven-plugin#431)) [@​dependabot](https://github.com/dependabot) #### 👻 Maintenance - Remove Log4j 1.2.x from ITs ([#​437](mojohaus/exec-maven-plugin#437)) [@​slawekjaranowski](https://github.com/slawekjaranowski) #### 🔧 Build - Use Maven 3.9.7 and 4.0.0-beta-3 ([#​433](mojohaus/exec-maven-plugin#433)) [@​slawekjaranowski](https://github.com/slawekjaranowski) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This MR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
@Nullable
annotations to be next to type and enable theAnnotationPosition
Error Prone check