As pointed by Paul B Mahol <onemda@gmail.com> the previous code could lead to null pointer dereference.