Android studio seems to think SparseArray
values cannot be null
.
When I write
public static void foo() {
SparseArray<Object> sparseArray = new SparseArray<Object>();
sparseArray.put(0, null);
if (sparseArray.valueAt(0) == null)
Log.d("MyClass", "Hello World");
}
I get the warning
condition 'sparseArray.valueAt(0) == null' is always 'false'
I'd just like to know what annotation or comment I need to put to get rid of the warning. I don't want to disable inspections, just get rid of this particular warning. Thanks.
To persistently configure which rules are run, you can create a file named lint. xml in the root directory of your project (next to the manifest file). Lint will automatically look at this file and use it to ignore warnings. Gradle, Android Studio and Eclipse will also use this configuration file if present.
The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. When using Android Studio, configured lint and IDE inspections run whenever you build your app.
You can suppress inspections locally with //noinspection <inspectionname>
.
For example:
//noinspection ConstantConditions
if (sparseArray.valueAt(0) == null)
gets rid of this false warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With