This seems weird. Maybe change the if statement to but == null, add the log statement to the if part and remove the else?