You are calling extras.getString("ActionBar")
twice. Once you check the return
ed value against null
(but never use it) and once you use it without checking it against null
. Now, maybe the contract of that function says that if it is called with identical arguments, it will always return
identical values, but this need not be the case and your IDE probably doesn't know.
You should store the return
value in a (preferably final
) variable, then the warning should go away.
if (extras != null) {
final String actbar = extras.getString("ActionBar");
if (actbar != null) {
if (actbar.equals("NO")) {
// ...
}
}
}
This might also be a performance advantage because you don't need to do getString
's work twice.
Anyway, if your code is full of such massive aggregations of if (o != null) { … }
checks, this might be an indication of code smell.