Code Refactor: Check null value to avoid null pointer exception.

Signed-off-by: Pengcheng Bian <pbian@actuate.com>