Fixed potential NPE due to many reads to an instance variable.

Factored out of #1895