5

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.

2
  • This indeed looks like a Lint issue as I checked SparseArray's sources and null should be pretty valid value. You should consider filling a bug report: code.google.com/p/android/issues/list Commented Aug 22, 2015 at 16:36
  • @MarcinOrlowski Thanks, I will do that. Commented Aug 22, 2015 at 16:39

1 Answer 1

5

You can suppress inspections locally with //noinspection <inspectionname>.

For example:

//noinspection ConstantConditions if (sparseArray.valueAt(0) == null) 

gets rid of this false warning.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.