While fixing another bug, found an NPE that sometimes is thrown, though too late to be logged. This fixes that case.