Merge "Add sanity check to avoid NullPointerException."