(#) LiveData value assignment nullability mismatch !!! ERROR: LiveData value assignment nullability mismatch This is an error, and is also enforced at build time when supported by the build system. For Android this means it will run during release builds. Id : `NullSafeMutableLiveData` Summary : LiveData value assignment nullability mismatch Severity : Fatal Category : Interoperability: Kotlin Interoperability Platform : Android Vendor : Android Open Source Project Identifier : androidx.lifecycle Feedback : https://issuetracker.google.com/issues/new?component=413132 Min : Lint 8.7+ Compiled : Lint 8.7+ Artifact : [androidx.lifecycle:lifecycle-livedata-core](androidx_lifecycle_lifecycle-livedata-core.md.html) Since : 2.3.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/main/java/androidx/lifecycle/lint/NonNullableMutableLiveDataDetector.kt) Tests : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/test/java/androidx/lifecycle/livedata/core/lint/NonNullableMutableLiveDataDetectorTest.kt) Copyright Year : 2019 This check ensures that LiveData values are not null when explicitly declared as non-nullable. Kotlin interoperability does not support enforcing explicit null-safety when using generic Java type parameters. Since LiveData is a Java class its value can always be null even when its type is explicitly declared as non-nullable. This can lead to runtime exceptions from reading a null LiveData value that is assumed to be non-nullable. !!! Tip This lint check has an associated quickfix available in the IDE. (##) Repackaged This lint check appears to have been packaged in other artifacts as well. Issue id's must be unique, so you cannot combine these libraries. Also defined in: * NullSafeMutableLiveData: LiveData value assignment nullability mismatch (this issue) * [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01](NullSafeMutableLiveData.md.html) * [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.0-alpha01](NullSafeMutableLiveData-2.md.html) (##) Including !!! This is not a built-in check. To include it, add the below dependency to your project. ``` // build.gradle.kts implementation("androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01") // build.gradle implementation 'androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01' // build.gradle.kts with version catalogs: implementation(libs.lifecycle.livedata.core) # libs.versions.toml [versions] lifecycle-livedata-core = "2.9.0-rc01" [libraries] # For clarity and text wrapping purposes the following declaration is # shown split up across lines, but in TOML it needs to be on a single # line (see https://github.com/toml-lang/toml/issues/516) so adjust # when pasting into libs.versions.toml: lifecycle-livedata-core = { module = "androidx.lifecycle:lifecycle-livedata-core", version.ref = "lifecycle-livedata-core" } ``` 2.9.0-rc01 is the version this documentation was generated from; there may be newer versions available. [Additional details about androidx.lifecycle:lifecycle-livedata-core](androidx_lifecycle_lifecycle-livedata-core.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: * Using a suppression annotation like this on the enclosing element: ```kt // Kotlin @Suppress("NullSafeMutableLiveData") fun method() { problematicStatement() } ``` or ```java // Java @SuppressWarnings("NullSafeMutableLiveData") void method() { problematicStatement(); } ``` * Using a suppression comment like this on the line above: ```kt //noinspection NullSafeMutableLiveData problematicStatement() ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="NullSafeMutableLiveData" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'NullSafeMutableLiveData' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore NullSafeMutableLiveData ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).