Avoid NPE when synchronizing on an object