Preventing NPE in a shutdown hook