TEZ-477. Fix NPEs etc caused by TEZ-433 (part of TEZ-398). (sseth)