Avoid accessing method on a null variable