-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Nullability Annotations to Java Classes] Enable and Configure UnknownNullness
Android Lint Check
#19116
Conversation
With that change the extra interop related 'UnknownNullness' Android Lint check gets enabled, which helps detect and flag some of the nullability interoperability issues for this project. For more info see: - Docs: https://developer.android.com/kotlin/interop#supported_checks - Check: https://googlesamples.github.io/android-custom-lint-rules/ checks/UnknownNullness.md.html ------------------------------------------------------------------------ You will also notice that this same 'UnknownNullness' configuration has been added on all the rest of the Android related 'library' modules. This is done because otherwise Lint is failing with the below 'CannotEnableHidden' related error: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Execution failed for task ':WordPress:lintJetpackWasabiDebug'. > Lint found errors in the project; aborting build. Fix the issues identified by lint, or add the issues to the lint baseline via `gradlew updateLintBaseline`. For more details, see https://developer.android.com/studio/write/lint #snapshot Lint found 1 errors, 0 warnings (403 errors filtered by baseline baseline.xml). First failure: /Users/.../WordPress/build.gradle:294: Error: Issue UnknownNullness was configured with severity warning in WordPress, but was not enabled (or was disabled) in library analytics [CannotEnableHidden] enable 'UnknownNullness' ~~~~~~~~~~~~~~~ Explanation for issues of type "CannotEnableHidden": Any issues that are specifically disabled in a library cannot be re-enabled in a dependent project. To fix this you need to also enable the issue in the library project. (This also applies for issues that are off by default; they cannot just be enabled in a dependent project; they must also be enabled in all the libraries the project depends on.) The full lint text report is located at: /Users/.../WordPress/build/intermediates/ lint_intermediate_text_report/jetpackWasabiDebug/ lint-results-jetpackWasabiDebug.txt - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
The default severity for 'UnknownNullness' is 'Warning'. This change updates that to 'Informational'. This is done for two main reasons: 1. To treat this kind of warnings as informational only, a light typo like of a warning in AS. 2. To avoid failing the build since all Lint warnings are treated as errors for this project (see 'warningsAsErrors = true' configuration).
65acac2
to
001b076
Compare
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.
This is working for me when I run ./gradlew lint
, but it isn't showing up in the IDE, for whatever reason 🤷♂️ . For that, I had to enable the rule in the settings, which introduced this diff:
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index d727ff611a..dd9b6310c3 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,6 +1,7 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
+ <inspection_tool class="AndroidLintUnknownNullness" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ClassName" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<scope name="Tests" level="INFORMATION" enabled="true" />
</inspection_tool>
I was a bit surprised that this wasn't showing up as informational automatically in Android Studio, so feel free to include this as well, or ignore.
Do we also want to do this, or is something else causing th
@@ -291,6 +291,7 @@ android { | |||
checkGeneratedSources = true | |||
lintConfig file("${project.rootDir}/config/lint/lint.xml") | |||
baseline file("${project.rootDir}/config/lint/baseline.xml") | |||
enable += 'UnknownNullness' |
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.
Thanks for using the +=
enabling here 👍
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.
All yours, thanks for suggesting it Matt! ❤️
👋 @mkevins and thanks for the review! 🙇 ❤️ 🚀
Yeap, I noticed that too, but I chose to ignore it since we will anyway have our own custom Android Lint rule enabled soon, which will anyway do that for us. IMHO, having that on the Lint report and it reporting the total number is enough for now, at least for the work currently in-progress from my side.
Nicely done Matt and good find. 🌟 To be honest, personally, I am against updating any
Yes, same here, but then again, I understanding that this isn't Android's official-official check, just an extra custom rule on their side. Thus, maybe they just don't want that to be as embedded with the AS warnings... 🤷
As per my above reasonings, I would personally like to ignore that. PS: One more reason to ignore that at this point of time, and until someone asks for it, is because this might conflict with our own custom Android Lint rule and checks, that is, when we end-up enabling those.
😅 ❓ 😊 |
I'm not sure why my comment got cut off 😅 , but I think it said "the missing highlights?" at the end. Anyway, I agree, especially since we'll have our own rule soon, no need to modify the |
Awesome @mkevins , once more thanks for the excellent review and for always sharing great suggestions! 🥇 |
Parent #18904
Closes #19113
This PR enabled and configures the extra interop related
UnknownNullness
Android Lint check to help detect and flag some of the nullability related interoperability issues, that is, issues in Java for Kotlin consumption.For more info see:
To test:
Interoperability:Kotlin Interoperability
related section on the Lint report is shown and reporting some few thousand of warnings (WordPress + Jetpack).jetpack
+wasabi
+debug
variant, I got4265
such warnings, configured to beinformational
only so that they don't fail the build, see screenshot below:Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
To test
section above.What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txt
if necessary.UI Changes testing checklist: