Condition cursor != null is always true