Merge "Add tests to prevent NPE regression." into pi-dev