Revert "Fixed potential NPE"

This reverts commit fcc648d0b8f008f735be7c66720c4d3a2a897f52.
Revert "Revert "Fixed potential NPE""

This reverts commit 3ae5f191194f964e287b0ca1ed2120d368e0773f.