Fix NPE.
Merge pull request #1233 from KostyaSha/fix

Fix NPE.