Prevent NPE trying to call toString on a null object