backport of NPE fix to release branch