Avoid unnecessary dereferencing of potential null pointers

Change-Id: Iba21dd394010a162a52bb576400cbbb9a9aad537