Fix NPE in rare situations