I found an interesting Lint inspection that I can't explain. I know Java crazy hidden stuff, so I'd like to understand what's going on here. Maybe I can impress my friends with super nerdy knowledge.
Here's a snippet of the offending code:
public void awesomeMethod()
{
final int[] hungryPeople = getHungryPeople();
if ( hungryPeople != null ) // <---- Lint says that this can never be null?
{
solveWorldHunger( true );
tellEveryone( false );
}
}
Here's the related (relevant) method:
public int[] getHungryPeople()
{
// Get hungry people data from the class's Android Intent field
final int[] values = mIntent.getIntArrayExtra( HUNGRY_PEOPLE );
if ( null != values )
{
return Arrays.copyOf( values, values.length );
}
return null;
}
Is there something I'm missing here?
You are returning
null
outside the method, you need to return insidegetHungryPeople()
in casevalues
isnull
.